Re: [R] randomly select duplicated entries

2008-07-09 Thread Marc Schwartz
on 07/09/2008 02:17 PM Juliet Hannah 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

Re: [R] randomly select duplicated entries

2008-07-09 Thread jim holtman
How about this: > 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() > # split by the id and then choose one > x <- lapply(split(dat, dat$Id), function(.grp){ + .grp[sample(seq(length(.grp)), 1)

Re: [R] randomly select duplicated entries

2008-07-09 Thread Henrique Dallazuanna
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

[R] randomly select duplicated entries

2008-07-09 Thread Juliet Hannah
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 th