[R] Merge selected list element by name

Mohammad Tanvir Ahamed mashranga at yahoo.com
Thu Apr 13 19:33:06 CEST 2017


Thanks for your code. 
But this is not the way i am expecting . 

I want to merge (Union) "a" and "c" and my expected output is 

> kk1
$a_c
 [1]  1  2  3  4  5  6  7  8  9 10 11

$b
[1]  6  7  8  9 10


Note : I worte the code kk1<- list(a_c = 1:11, b = 6:10) just to show by expected outcome. But i am expecting the resulting code will naming "a_c" by itself also.
Hope i can make clear about problem. 

 

 
Tanvir Ahamed 
Göteborg, Sweden  |  mashranga at yahoo.com 



________________________________
From: Rui Barradas <ruipbarradas at sapo.pt>

lp at r-project.org> 
Sent: Thursday, 13 April 2017, 18:37
Subject: Re: [R] Merge selected list element by name



Hello,

There's no need to send the same question twice, we've got it at the 
first try.
Maybe I don't understand but is this it?

kk1 <- list(a_c = union(kk$a, kk$c), b = kk$b)
kk1
$a_c
  [1]  1  2  3  4  5  6  7  8  9 10 11

$b
[1]  6  7  8  9 10


Hope this helps,

Rui Barradas


Em 13-04-2017 15:59, Mohammad Tanvir Ahamed via R-help escreveu:
>
> Hi,
>
> I have a list like
>
> kk<- list (a = 1:5, b = 6:10, c = 4:11)
>
>
> Now i want to merger (Union) the list element "a" and "c" by name .
>
>
> My expected outcome is
>
> kk1<- list(a_c = 1:11, b = 6:10)
>
>
>
> I can do it with several lines of code. But can any one have idea to do efficiently/ quickly on a big data with less code.
>
> Thanks in advance.
>
>
> Tanvir Ahamed
>

>
> ______________________________________________
> 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.

>



More information about the R-help mailing list