I have a data frame with two columns. I would like to create a new data frame which lists all values of second column for each unique value of the first column in the first data frame. I do not want to use data tables.
After several trials and errors, I came up with the following. I would like to know if there is an easier (one-step?), faster, or more optimal way to achieve this, since the actual data frames I will be running this on are very large.
> df <- data.frame( a=c( 1, 1, 2, 2, 3 ), b=c( 6:10 ) );
> df
a b
1 1 6
2 1 7
3 2 8
4 2 9
5 3 10
> df2 <- data.frame( a=unique( df$a ) )
> temp <- dlply( df, .(a), function( x ) data.frame( bs=x$b ) );
> df2$bs <- lapply( temp, function( x ) x$bs )
> df2
a bs
1 1 6, 7
2 2 8, 9
3 3 10
>
Thanks.