[R] data frames; maybe aggregate?

Jonathan Reichel jbreichel at gmail.com
Fri Feb 12 23:45:49 CET 2010


Hi all,
    Another one:

Given a data frame with two columns, where the first column (let's
call it 'id') has redundant entries, I'd like to get, for each unique
value in 'id', a list or vector of all the values from the second
column that corresponded to that value.

Example:

> df <- data.frame('id'=c('a','b','a','c','b','a'),'value'=c(6,4,2,9,1,7))
> df
  id value
1  a     6
2  b     4
3  a     6
4  c     9
5  b     1
6  a     7

I'd like some kind of output resembling something along these lines:

a: 6, 6, 7
b: 4, 1
c: 9

Any ideas would be appreciated!

Best,
Jonathan



More information about the R-help mailing list