
高效学习
|
199
set.seed(1)
example_df = data.frame(x = rnorm(4), y = rnorm(4), z = sample(LETTERS, 4))
需要注意的是,set.seed 的 调用确保了:所有执行该代码人都能获得
相同随机数。另外,你可使用
R
自带数据集中某个(library(help =
"datasets"))。
如果生成演示数据集不可行,那么针对实际数据集使用 dput。这将生成一个
对象的
ASCII
文本表达式,从而确保任何可重建该对象:
dput(example_df)
#> structure(list(
#> x = c(-0.626453810742332, 0.183643324222082, -0.835628612410047,
#> 1.59528080213779),
#> y = c(0.329507771815361, -0.820468384118015, 0.487429052428485,
#> 0.738324705129217),
#> z = structure(c(3L, 4L, 1L, 2L), .Label = c("J", "R", "S", "Y"),
#> class = "factor"
))
,
#> .Names = c("x", "y", "z"), row.names = c(NA, -4L), class = "data.frame")
最小案例
你不应该直接拷贝你的代码,而后直接粘贴到你的问题中。你的整个函数不 ...