Try this: do.call(rbind, lapply(split(dat, dat$Id), function(x)x[sample(1:nrow(x), 1),]))
On 7/9/08, Juliet Hannah <[EMAIL PROTECTED]> wrote: > Using this data as an example > > dat <- read.table(textConnection("Id myvar > 12 1 > 12 2 > 12 6 > 34 9 > 34 4 > 34 8 > 65 15 > 65 23"), header = TRUE) > closeAllConnections() > > how can I create another data set that does not have duplicate entries > for 'Id', but the included values > are randomly selected from the available ones. > > Thanks! > > Juliet > > ______________________________________________ > 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. > -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O ______________________________________________ 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.