# [R] Help Help with sampling

Alex99 loyola9988 at yahoo.com
Wed Oct 15 16:52:27 CEST 2008

```Thanks for the reply Peter,

that works BUT the reason I didn't use it, is because I need to calculate
the mean and Standard deviation for S1,S2,S3 and S4 in each sample. which
means I'll have 5 means for S1, and 5 means for S2 and 5 means for S3 and 5
means for S4 (and at the end I have to get the average of the means for each
'S').
I used the following:

for(i in 1:5) {temp<-sample(A3,3, replace=F)
+ Trans=t(temp)
+ Avg=mean(Trans)
+ show(temp)
+ show(Trans)
+ show(Avg)}

the reason I used Transpose is to get the R to give me the mean for S's. but
what I get is just one mean for each sample. not the mean for each S.
any suggestion how to do it?

thanks again for all your help

Peter Dalgaard wrote:
>
> Alex99 wrote:
>> Hi everyone,
>>
>> I have a dataset(named "Mydata") which includes 4 different variables
>> named;
>> s1,s2,s3,s4 .Each variable(symptom) has 14 patients.
>> I need to use random sampling to make, 5 different samples from my data
>> with
>> 5 patients in each sample. i.e. using all 4 variables I need to make 5
>> different samples by changing patients(with 5 patients in each sample).
>>
>>
>>    X8 X9 X10 X102 X110 X177 X283 X284 X286 X292 X297 X306 X308 X314
>> s1  0  1   0    0    0    1    0    0    0    0    0    0    0    0
>> s2  0  0   0    0    1    0    0    0    0    0    0    0    1    0
>> s3  0  1   0    0    0    0    0    0    0    0    0    0    1    0
>> s4  1  0   0    0    1    0    0    0    0    1    0    0    0    0
>>
>>
>> I used this code:
>>
>> temp=list(NULL)
>> for(i in 1:5) {temp[i]<-sample(Mydata,5, replace=F)} show(temp)
>>
>> but I get the following error:
>> "number of items to replace is not a multiple of replacement length"
>>
>> any idea why I get this eeror message and how can I fix it?
>> Thanks a lot.
>>
>>
> The direct cause is that you are not using temp[[i]]<-, but I don't
> think that sample() construct does what I think you think it does
> either. You might want to use replicate() instead, as in
>
>  replicate(2,airquality[sample(1:153,5, replace=F),], simplify=F)
>
> --
>    O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
>   c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
>  (*) \(*) -- University of Copenhagen   Denmark      Ph:  (+45) 35327918
> ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)              FAX: (+45) 35327907
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help