Something like:
dat[dat$ID %in% sample(unique(dat$ID), 3), ]
or
subset(dat, ID %in% sample(unique(ID), 3))
which I find to be more readable.
______________________________________________ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html