楼主: Lisrelchen
1042 1

Building an R loop for random sampling [推广有奖]

  • 0关注
  • 62粉丝

VIP

已卖:4194份资源

院士

67%

还不是VIP/贵宾

-

TA的文库  其他...

Bayesian NewOccidental

Spatial Data Analysis

东西方数据挖掘

威望
0
论坛币
50288 个
通用积分
83.6906
学术水平
253 点
热心指数
300 点
信用等级
208 点
经验
41518 点
帖子
3256
精华
14
在线时间
766 小时
注册时间
2006-5-4
最后登录
2022-11-6

楼主
Lisrelchen 发表于 2014-4-19 12:24:36 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币

I am sampling from a file containing a list of many values eg:

312313.3424344412334.92321312353532

and using R to randomly sample from this list:

list = read.table("data")out <-sample(list,50,replace=TRUE)out.mean<-mean(out)out.mean

Could somebody please show me how to put this into a loop, so that I can perform this procedure 1000 times and take the mean of the 1000 means that this will generate?

Thank you very much in advance!


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:Sampling Building random Build rand values file

沙发
Lisrelchen 发表于 2014-4-19 12:25:07
An alternative solution could be (keep in mind what @Tyler Rinker just said about replicate)

Data <- read.table(text='
312313.34
243444
12334.92
321312
353532', header=FALSE)

Data <- as.numeric(as.matrix((Data)))

set.seed(007)
Means <- replicate(1000, mean(sample(Data,50,replace=TRUE)))
Means consists of 1000 mean each one for every subsample of size 50. If you want the mean of the means do this:

mean(Means)
What you're trying to do sounds like a bootstrapping or something similar to resample techniques for bias reduction (I guess).

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2026-1-29 02:32