Thanks again Jorge, but when I type in lapply(res,function(x) rbind(rowMeans(x)) it's like it's waiting for something else, it doesnt run. I tried "help(lapply)" to learn more about lappy but didnt give me any result. could you tell me why it doesnt run and what is lapply for?
Thanks a lot for all your help Jorge Ivan Velez wrote: > > Dear Alex, > Is this what you want? > > my=read.table(textConnection(" > X8 X9 X10 X102 X110 X177 X283 X284 X286 X292 X297 X306 X308 X314 > 0 1 0 0 0 1 0 0 0 0 0 0 0 0 > 0 0 0 0 1 0 0 0 0 0 0 0 1 0 > 0 1 0 0 0 0 0 0 0 0 0 0 1 0 > 1 0 0 0 1 0 0 0 0 1 0 0 0 > 0"),header=TRUE) > closeAllConnections() > rownames(my)=paste('s',1:4,sep="") > > # Using 5 samples only > res=replicate(5,my[,sample(colnames(my),5)],simplify=FALSE) > > # mean > lapply(res,function(x) rbind(rowMeans(x)) > > # standard deviation > lapply(res,function(x) apply(x,1,sd,na.rm=TRUE)) > > > HTH, > > Jorge > > > On Wed, Oct 15, 2008 at 10:58 AM, Alex99 <[EMAIL PROTECTED]> wrote: > >> >> Thanks for the reply Jorge, >> >> 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 >> >> Jorge Ivan Velez wrote: >> > >> > Dear Alex, >> > Is this what you want? >> > >> > # Data set >> > my=read.table(textConnection(" >> > X8 X9 X10 X102 X110 X177 X283 X284 X286 X292 X297 X306 X308 X314 >> > 0 1 0 0 0 1 0 0 0 0 0 0 0 0 >> > 0 0 0 0 1 0 0 0 0 0 0 0 1 0 >> > 0 1 0 0 0 0 0 0 0 0 0 0 1 0 >> > 1 0 0 0 1 0 0 0 0 1 0 0 0 >> > 0"),header=TRUE) >> > closeAllConnections() >> > rownames(my)=paste('s',1:4,sep="") >> > >> > # Samples >> > res=list() >> > for(i in 1:5) res[[i]]<- my[,sample(colnames(my),5)] >> > res >> > >> > HTH, >> > >> > Jorge >> > >> > >> > On Wed, Oct 15, 2008 at 10:07 AM, Alex99 <[EMAIL PROTECTED]> 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. >> >> >> >> -- >> >> View this message in context: >> >> http://www.nabble.com/Help-Help-with-sampling-tp19994275p19994275.html >> >> Sent from the R help mailing list archive at Nabble.com. >> >> >> >> ______________________________________________ >> >> R-help@r-project.org mailing list >> >> https://stat.ethz.ch/mailman/listinfo/r-help >> >> PLEASE do read the posting guide >> >> http://www.R-project.org/posting-guide.html >> >> and provide commented, minimal, self-contained, reproducible code. >> >> >> > >> > [[alternative HTML version deleted]] >> > >> > ______________________________________________ >> > R-help@r-project.org mailing list >> > https://stat.ethz.ch/mailman/listinfo/r-help >> > PLEASE do read the posting guide >> > http://www.R-project.org/posting-guide.html >> > and provide commented, minimal, self-contained, reproducible code. >> > >> > >> >> -- >> View this message in context: >> http://www.nabble.com/Help-Help-with-sampling-tp19994275p19995327.html >> Sent from the R help mailing list archive at Nabble.com. >> >> ______________________________________________ >> R-help@r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > > -- View this message in context: http://www.nabble.com/Help-Help-with-sampling-tp19994275p19997239.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.