Collapse data matrix with extra info separated by commas
On Mon, Apr 6, 2009 at 10:40 AM, baptiste auguie <ba208 at exeter.ac.uk> wrote:
Here's one attempt with plyr, hopefully Hadley will give you a better
solution ( I could not get cast() to do it either)
test <-
data.frame(a=c("A","A","A","A","B","B","B"),b=c(1,1,2,2,1,1,1),c=sample(1:7))
ddply(test,.(a,b),.fun=function(.) paste(.)[3])
This is a problem that currently isn't very easy to solve in plyr (but I'm working on it). About the best you can do is: ddply(test, ~ a + b, colwise(paste, .(c)), collapse =",") (this is basically equivalent to your suggestion) Hadley