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
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)
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
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
4 matches
Mail list logo