随机采样100次,将数据集放入列表中
我有一个带有多个ID的数据集,看起来像这样(缩短版本):
ID Value
bear 1 1
bear 1 2
bear 1 5
bear 2 2
bear 2 3
bear 2 1
bear 2 1
bear 2 4
我想每个ID号进行采样一行,然后将这些行分为数据框架,例如:
ID Value
bear 1 2
bear 2 1
我想将此随机采样100次,取结果100个数据集,并将其作为列表中的元素。
关于如何这样做的任何想法吗?使用某些apply()/lapply()/sapply()函数或循环?
I have a dataset with multiple ID's that looks like this (shortened version):
ID Value
bear 1 1
bear 1 2
bear 1 5
bear 2 2
bear 2 3
bear 2 1
bear 2 1
bear 2 4
I would like to sample one row per ID number and make those rows into a data frame, like this for example:
ID Value
bear 1 2
bear 2 1
I then want to this random sampling 100 times, take the resulting 100 datasets and make them elements in a list.
Any thoughts on how to do this? Either using some of the apply()/lapply()/sapply() functions or a loop?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我们可以使用
rerun
与slice_sample
-重新运行
复制采样的输出n
times,然后返回list
list < /代码>
We may use
rerun
withslice_sample
-rerun
replicates the sampled outputn
times and return alist