[R] concatenating lists elementwise

Huntsinger, Reid reid_huntsinger at merck.com
Mon Oct 18 17:58:39 CEST 2004

I don't know of a way other than brute force:

> list.3 <- list()
> for (i in union(names(list.1),names(list.2))) 
      list.3[[i]] <- union(list.1[[i]],list.2[[i]])
> list.3
[1] "hot"      "cold"     "lukewarm"

[1] "big"     "medium"  "massive" "tiny"   

I suppose one could write a method for "merge" for lists.

Reid Huntsinger

-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Robin Hankin
Sent: Monday, October 18, 2004 8:01 AM
To: r-help at stat.math.ethz.ch
Subject: [R] concatenating lists elementwise


How do I concatenate two lists element-by-element?


list.1 <- list(temperature=c("hot","cold") , size=c("big","medium"))
list.2 <- list(temperature=c("lukewarm")   , size=c("massive","tiny"))

list.wanted  <- list(temperature=c("hot","cold","lukewarm") ,

(the lists are dimnames() of an array).

Robin Hankin
Uncertainty Analyst
Southampton Oceanography Centre
SO14 3ZH
tel +44(0)23-8059-7743
initialDOTsurname at soc.soton.ac.uk (edit in obvious way; spam precaution)

R-help at stat.math.ethz.ch mailing list
PLEASE do read the posting guide!

More information about the R-help mailing list