[R] Concatenate two lists replacing elements with the same name.

Gabor Grothendieck ggrothendieck at gmail.com
Tue Jul 19 19:20:48 CEST 2016


Try this:

    Reduce(modifyList, list(x, y, z))

On Tue, Jul 19, 2016 at 12:34 PM, Luca Cerone <luca.cerone at gmail.com> wrote:
> Dear all,
> I would like to know if there is a function to concatenate two lists
> while replacing elements with the same name.
>
> For example:
>
> x <- list(a=1,b=2,c=3)
> y <- list( b=4, d=5)
> z <- list(a = 6, b = 8, e= 7)
>
> I am looking for a function "concatfun" so that
>
> u <- concatfun(x,y,z)
>
> returns:
>
> u$a=6
> u$b=8
> u$c=3
> u$d=5
> u$e=7
>
> I.e. it combines the 3 lists, but when names have the same value it
> keeps the most recent one.
>
> Does such a function exists?
>
> Thanks for the help,
>
> Cheers,
> Luca
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.



-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com



More information about the R-help mailing list