[R] combine the data frames into comma separated list.
Dr. D. P. Kreil (Boku)
David.Kreil at boku.ac.at
Tue Jun 14 02:57:39 CEST 2011
now that's beautiful! :-)
Many thanks,
David.
> Try this where DF1, DF2 and DF3 are the data frames:
>
> L <- list(DF1, DF2, DF3)
> merge.all <- function(...) merge(..., all = TRUE)
> Reduce(merge.all, lapply(L, function(x) aggregate(x[2], x[1], toString)))
>
> The last line gives this:
>
> Src Target1 Target2 Target3
> 1 1 aaa, bbb, ccc <NA> xx
> 2 2 aaa aaaa <NA>
> 3 3 ddd dddd yy
> 4 4 <NA> bbbb, eeee, ffff <NA>
> 5 5 <NA> <NA> zz
> 6 6 <NA> <NA> tt, uu
More information about the R-help
mailing list