Re: [R] Sampling problem

2010-11-16 Thread wangwallace
yes, the data.frame is exactly the same as the one I posted earlier. I was trying to see if the loop function works. And I got that message. here below is the syntax I was trying to run, followed by the error message at the end: > sampleX<-function(X,nGrp1,nsamples){if(nGrp1>=4)stop("can't sampl

Re: [R] Sampling problem

2010-11-16 Thread Michael Bedward
On 16 November 2010 16:10, wangwallace wrote: > > Michael, I really appreciate your help. > > but I got the following error message when I wan trying to run the function > written by you: > > Error in out[i, ] <- apply(help[, c(grp1 + 1, grp2 + 5)], 2, sample, 1) : >  number of items to replace is

Re: [R] Sampling problem

2010-11-16 Thread wangwallace
Michael, I really appreciate your help. but I got the following error message when I wan trying to run the function written by you: Error in out[i, ] <- apply(help[, c(grp1 + 1, grp2 + 5)], 2, sample, 1) : number of items to replace is not a multiple of replacement length I am not quite sure

Re: [R] Sampling problem

2010-11-15 Thread Michael Bedward
Hello, Is this what you want ? sampleX <- function(X, nGrp1, nsamples) # X is matrix or data.frame with cols for two groups of variables # with grp1 in cols 2:5 and grp2 in cols 6:9 # # nGrp1 <- number of variables to sample from group 1 # # nsamples <- number of rows in output matrix if (nGrp

[R] Sampling problem

2010-11-15 Thread wangwallace
Hey, I am hoping someone can help me with a sampling question. I have a data frame of 8 variables (the first column is the subjects' id): SubIDCSE1 CSE2 CSE3 CSE4 WSE1 WSE2 WSE3 WSE4 1 6 5 6 2 6 22 4 2 6 4