[R] concatenating lists elementwise
Prof Brian Ripley
ripley at stats.ox.ac.uk
Mon Oct 18 14:16:49 CEST 2004
On Mon, 18 Oct 2004, Robin Hankin wrote:
> How do I concatenate two lists element-by-element?
> Example:
>
> 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") ,
> size=c("big","medium","massive","tiny"))
>
>
>
> (the lists are dimnames() of an array).
mapply(c, list.1, list.2)
(but it loses the list names, so copy them across).
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-help
mailing list