Try this: > x V1 V2 V3 1 1 15 34 2 1 4 66 3 1 24 65 4 2 23 47 5 2 9 36 6 3 58 9 7 3 38 64 8 3 12 64 9 3 4 15 10 4 1 88 11 4 23 90
x[tapply(seq(nrow(x)), x$V1, sample, 1),] On Tue, Nov 9, 2010 at 9:01 PM, Achim Eberhart < a.eberh...@pgrad.unimelb.edu.au> wrote: > G'day R-helpers, > > I want to subsample rows of a large table based on the value in its first > column. Of all rows sharing the same value in the first column I want to > RANDOMLY extract only one. > Thanks in advance, > > Achim > > example input > > 1 15 34 > 1 4 66 > 1 24 65 > 2 23 47 > 2 9 36 > 3 58 9 > 3 38 64 > 3 12 64 > 3 4 15 > 4 1 88 > 4 23 90 > > desired output > > 1 4 66 > 2 23 47 > 3 12 64 > 4 1 88 > > ______________________________________________ > 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 [[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.