Re: [R] combining lists of pairs

From: Charles C. Berry <cberry_at_tajo.ucsd.edu>
Date: Thu, 17 Jul 2008 16:14:06 -0700

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

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. Received on Thu 17 Jul 2008 - 23:19:23 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 17 Jul 2008 - 23:31:51 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive