[R] Question about collapse/aggregate and avoidance of loops

Patrick Burns pburns at pburns.seanet.com
Thu Jan 29 09:46:01 CET 2009


I think you are looking for

split(author, id)


Patrick Burns
patrick at burns-stat.com
+44 (0)20 8525 0696
http://www.burns-stat.com
(home of "The R Inferno" and "A Guide for the Unwilling S User")

Weiss, Bernd wrote:
> Dear all,
>
> given the following data
>
> ## original data
> id <- c(1,1,1,2,2,3)
> author <- c("A","B","C","D","E","F")
> tmp <- data.frame(id,author)
> tmp
>
>
> > tmp
>   id author
> 1  1      A
> 2  1      B
> 3  1      C
> 4  2      D
> 5  2      E
> 6  3      F
>
> What is the best (most efficient/vectorized/avoiding loops) approach 
> to obtain the following data frame?
>
> id     author
> 1    "A, B, C"
> 2     "D, E"
> 3    "F"
>
>
> Thanks for your help,
>
> Bernd
>
>
>
>
>
> > version
>                _
> platform       i386-pc-mingw32
> arch           i386
> os             mingw32
> system         i386, mingw32
> status         Patched
> major          2
> minor          8.1
> year           2008
> month          12
> day            22
> svn rev        47296
> language       R
> version.string R version 2.8.1 Patched (2008-12-22 r47296)
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>




More information about the R-help mailing list