Hello, I am trying to randomly select rows with unique values in columns 1 and 2. I want to generate multiple subsets to estimate a statistic for each data set. Below is a simplified example. L1 L2 L3 L4 L5 1 a b 1 2 3 2 a c 4 5 6 3 a d 7 8 9 4 a e 10 11 12 5 a f 13 14 15 6 b c 16 17 18 7 b d 19 20 21 8 b e 22 23 24 9 b f 25 26 27 10 c d 28 29 30 11 c e 31 32 33 12 c f 34 35 36 13 d e 37 38 39 14 d f 40 41 42 15 e f 43 44 45 Could you please give directions to where to start? I have tried eliminating duplicates and finding unique rows but no successful to make it random. Thanks Hasan -- View this message in context: http://r.789695.n4.nabble.com/Randomly-selecting-rows-with-unique-values-in-two-columns-tp3845504p3845504.html Sent from the R help mailing list archive at Nabble.com.
R. Michael Weylandt <michael.weylandt@gmail.com>
2011-Sep-27 00:52 UTC
[R] Randomly selecting rows with unique values in two columns
It sounds like you've already done the hard(er) part: just use sample(nrow, noWanted) now to pick which rows to select. Michael Weylandt On Sep 26, 2011, at 5:42 PM, hasan <halhaddad at ucdavis.edu> wrote:> Hello, > > I am trying to randomly select rows with unique values in columns 1 and 2. I > want to generate multiple subsets to estimate a statistic for each data set. > Below is a simplified example. > > L1 L2 L3 L4 L5 > 1 a b 1 2 3 > 2 a c 4 5 6 > 3 a d 7 8 9 > 4 a e 10 11 12 > 5 a f 13 14 15 > 6 b c 16 17 18 > 7 b d 19 20 21 > 8 b e 22 23 24 > 9 b f 25 26 27 > 10 c d 28 29 30 > 11 c e 31 32 33 > 12 c f 34 35 36 > 13 d e 37 38 39 > 14 d f 40 41 42 > 15 e f 43 44 45 > > Could you please give directions to where to start? I have tried eliminating > duplicates and finding unique rows but no successful to make it random. > > Thanks > > Hasan > > -- > View this message in context: http://r.789695.n4.nabble.com/Randomly-selecting-rows-with-unique-values-in-two-columns-tp3845504p3845504.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at 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.
David Winsemius
2011-Sep-27 00:53 UTC
[R] Randomly selecting rows with unique values in two columns
On Sep 26, 2011, at 5:42 PM, hasan wrote:> Hello, > > I am trying to randomly select rows with unique values in columns 1 > and 2. I > want to generate multiple subsets to estimate a statistic for each > data set. > Below is a simplified example. > > L1 L2 L3 L4 L5 > 1 a b 1 2 3 > 2 a c 4 5 6 > 3 a d 7 8 9 > 4 a e 10 11 12 > 5 a f 13 14 15 > 6 b c 16 17 18 > 7 b d 19 20 21 > 8 b e 22 23 24 > 9 b f 25 26 27 > 10 c d 28 29 30 > 11 c e 31 32 33 > 12 c f 34 35 36 > 13 d e 37 38 39 > 14 d f 40 41 42 > 15 e f 43 44 45I think this is isomorphic to a question in the last couple of days on StackOverflow: http://stackoverflow.com/questions/7536218/how-do-i-take-subsets-of-a-data-frame-according-to-a-grouping-in-r-tricky-aggre/7536610#7536610 (I don't think the -1 score on my tapply solution is exactly fair. but I suspect that Ari has moved on to other things and is not going back to check up on edits. I think w=either solution should provide a random selection within groups.)> > Could you please give directions to where to start? I have tried > eliminating > duplicates and finding unique rows but no successful to make it > random. > > Thanks > > Hasan > > -- > View this message in context: http://r.789695.n4.nabble.com/Randomly-selecting-rows-with-unique-values-in-two-columns-tp3845504p3845504.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at 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.David Winsemius, MD West Hartford, CT
Seemingly Similar Threads
- [LLVMdev] loop vectorizer: Unexpected extract/insertelement
- [LLVMdev] loop vectorizer: Unexpected extract/insertelement
- [LLVMdev] indirectbr and phi instructions
- [LLVMdev] loop vectorizer: Unexpected extract/insertelement
- NHW Project - quality improvement for -l4,-l5 settings