我只是试图通过取不同概率的随机样本的均值来说明中心极限定理。分布。我有以下代码,其中我增加了指数分布的样本大小。
set.seed(12577) # for reproducability
n <- 50
lambda <- 0.2
out <- rexp(5000, lambda)
for(i in seq_along(sample_size)) {
out <- cbind(out, c(replicate(sample_size[i], mean(rexp(n, lambda))) , rep(NA, 5000 - sample_size[i] )))
}
out <- as.data.frame(out)
names(out) <- c("EXP_SAMPLE_5000", paste0("RND_SAMPLE_", sample_size))
我想使用ggvis来选择不同的列来创建直方图。我尝试了以下但是没有工作:
out %>% ggvis(x = input_select(label = "Choose what to plot:",
choices = names(out),
selected = "EXP_SAMPLE_5000",
map = as.name)) %>% layer_histograms()
更新:根据@Martin Schmelzer的评论,我添加了假人,但现在直方图没有意义。
out %>% ggvis(x = ~ 100, y = input_select(label = "Choose what to plot:",
choices = names(out),
#multiple=TRUE,
map = as.name)) %>% layer_histograms()