[R] combining lists of pairs
Charles C. Berry
cberry at tajo.ucsd.edu
Fri Jul 18 01:14:06 CEST 2008
On Thu, 17 Jul 2008, olvrmrs at aol.com wrote:
> Hi everybody,
>
> This has been causing me some trouble:
>
> I want to combine several lists of pairs into a single?vector but keep the pairs together. The lists are of the form:
> (1)?x1 x2 x3... N?
> (2) y1 y2 y3..? N
>
> I would like to keep it this way, simply appending one list to another, e.g.
> (1) x1i x2i... x1j x2j... N
> (2) etc.
>
> A?method like c(...) does not achieve this. It creates a single list, disregarding the pairs.
Then you do not literally have a list of pairs.
You need to do this when posting:
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
Note:
> lp <- list(c(1,2),c(3,4),c(5,6))
> lp2 <- list(c(1,2),c(3,4),c(5,6))
> c(lp,lp2) # HA! A list of all pairs.
So c(...) works on a list of pairs.
=====
If what you have is a pair of vectors of atomic elements stored as a list,
you can use rbind( as.data.frame(list1), as.data.frame(list2) , ... )
If not, I might suggest you either convert your structure to a list of
pairs, or a data.frame, and use the one of the above approaches.
Or tell us what your object really is so we might better advise.
Hint see:
?str
and use it before replying.
HTH,
Chuck
>
> Is there a more efficient way of doing it?
>
> Thanks!
> Oliver Marshall
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>
Charles C. Berry (858) 534-2098
Dept of Family/Preventive Medicine
E mailto:cberry at tajo.ucsd.edu UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901
More information about the R-help
mailing list