Re: [R] vectorizing: selecting one record per group

2010-10-13 Thread David Winsemius
On Oct 13, 2010, at 4:17 PM, Erik Iverson wrote: Hello, There are probably many ways to do this, but I think it's easier if you use a data.frame as your object. The easy solution for the matrix you provide is escaping me at the moment. Perhaps using sampling to derive an index? A[ tapply(1

Re: [R] vectorizing: selecting one record per group

2010-10-13 Thread Henrique Dallazuanna
Try this: A <- data.frame(V1 = rnorm(100), V2 = runif(100), V3 = rep(c(1,2,3,4,5),20)) do.call(cbind, lapply(aggregate(. ~ V3, A, FUN = sample, size = 5), c)) On Wed, Oct 13, 2010 at 5:01 PM, Mauricio Romero < mauricio.rom...@quantil.com.co> wrote: > Hi, > > > > I want to select a subsample from

Re: [R] vectorizing: selecting one record per group

2010-10-13 Thread Erik Iverson
Hello, There are probably many ways to do this, but I think it's easier if you use a data.frame as your object. The easy solution for the matrix you provide is escaping me at the moment. One solution, using the plyr package: library(plyr) A <- data.frame(a = rnorm(100),b = runif(100), c = rep

[R] vectorizing: selecting one record per group

2010-10-13 Thread Mauricio Romero
Hi, I want to select a subsample from my data, choosing one record from each group. I know how to do this with a for. For example: lets say I have the data: A=cbind(rnorm(100),runif(100),(rep(c(1,2,3,4,5),20))) Where the third column is the group variable. Then what I want is to select 5