如何从R中的数据集中取出1万个样本?

发布于 2025-01-29 12:03:31 字数 227 浏览 2 评论 0原文

我想从具有2000行的数据框架中取出400个样本,而这样做的方法只是

s1 <- sample_n(t, 400) 

我想做10000次。我猜boot()是在这里使用的功能以避免过载,但我不知道我需要写些什么作为功能部分来获得我想要的东西,

boot(t, ?, 10000)

任何人都可以在这里帮助我吗?

I want to take a sample of 400 out of a data frame with 2000 rows, the way to do that is simply

s1 <- sample_n(t, 400) 

Now I want to do that 10000 times. I guess boot() is the function to use here to avoid an overload but I don't know what I need to write as the function part to get what I want

boot(t, ?, 10000)

Can anyone more experienced with r help me out here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情归归情 2025-02-05 12:03:31

您还可以使用sample_n重复<代码>重复像这样的随机示例:

library(dplyr)
bind_rows(replicate(10, df %>% sample_n(400), simplify = F)) 

请注意:将10到10000更改为10000次。

随机数据

df <- data.frame(v1 = runif(2000, 0, 1))

You can also replicate the random sample using sample_n like this:

library(dplyr)
bind_rows(replicate(10, df %>% sample_n(400), simplify = F)) 

Please note: change the 10 to 10000 for 10000 times.

Random data

df <- data.frame(v1 = runif(2000, 0, 1))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文