Hi: Try this:
# Function to generate one sample from the data frame sampler <- function(df) { s1 <- sample(nrow(df), 1, replace = FALSE) s2 <- sample(setdiff(1:nrow(df), s1), 2, replace = FALSE) list(sample1 = df[s1, grep('^C', names(df))], sample2 = df[s2, grep('^W', names(df))]) } sampler(mydf) # try it out on your data frame below # replicate the process 1000 times l <- vector('list', 1000) for(i in seq_along(l)) l[[i]] <- sampler(mydf) HTH, Dennis On Tue, Nov 16, 2010 at 9:53 AM, wangwallace <talentt...@gmail.com> wrote: > > Fabulicious!!!!!!!!!!!!!!!!! It worked!!! > > One more question, in the following data frame as posted above: > > SubID CSE1 CSE2 CSE3 CSE4 WSE1 WSE2 WSE3 WSE4 > 1 6 5 6 2 6 2 2 4 > 2 6 4 7 2 6 6 2 3 > 3 5 5 5 5 5 5 4 5 > 4 5 4 3 4 4 4 5 2 > 5 5 6 7 5 6 4 4 1 > 6 5 4 3 6 4 3 7 3 > 7 3 6 6 3 6 5 2 1 > 8 3 6 6 3 6 5 4 7 > > I want to draw the first random sample consisting of a row of integers > under > the first group of variables (CSE1, CSE2, CSE3, CSE4). For example, > assuming > the first draw yielded a sample of the first row (6, 5, 6, 2), now I want > to > draw another random sample consisting of two rows of integers under the > second group of variables (WSE1, WSE2, WSE3, WSE4). Also, for the second > draw, I want to restrict a vector I am going to sample from to only those > rows that are not correspond to SubID I have sampled. That is, I want to > sample two rows of integers under the second group of variables (WSE1, > WSE2, > WSE3, WSE4) from rows 2, 3, 4, 5, 6, 7, and 8. > > Also, I want to repeat this whole process (drawing 1 random row of integers > under the first group of variables first, AND then another two random rows > under the second group of variables) for 1000 times. Any ideas? would that > be possible to do it by just revising the syntax you wrote above? many > thanks!!! > -- > View this message in context: > http://r.789695.n4.nabble.com/Sampling-problem-tp3043804p3045352.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.