Liaw, Andy wrote: > 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.