Re: [R] manipulating elements of lists

From: talepanda <talepanda_at_gmail.com>
Date: Wed 10 Jan 2007 - 07:05:07 GMT

Maybe I misunderstand what you want to do, one solution is:

> l1

$a
[1] 1 2

$b
[1] 1 2 3

$c
[1] 1 2 3 4

> l2

  V1 V2
1 d nd
2 c nc
3 b nb
4 a na
> names(l1)<-sapply(names(l1),function(n)l2[l2$V1==n,2])
> l1

$na
[1] 1 2

$nb
[1] 1 2 3

$nc
[1] 1 2 3 4

On 1/10/07, Christoph Heibl <christoph.heibl@gmx.net> wrote:
> I want to manipulate lists as described below:
> Imagine these two lists:
>
> > list1
> $WR7
> [1] 1 2 3 4
>
> $YH5YH6
> [1] 3 4 5 6 7
>
> $YH4
> [1] 4 5
>
> $UC4UC8
> [1] 4 5 6 7 8 9
>
> > list2
> V1 V2
> 1 WR7 Averrhoa
> 2 ? Sarcotheca
> 3 YH5YH6 caesia
> 4 YH4 arbuscula
> 5 UC4UC8 rosea
> 6 ? acetosella
>
> How can I exchange the names(list1) by the entries in the second
> column of list2,
> if (a) length(list1) ≠ length(list2) and (b) the elements of both
> lists are not in the same order? Is there a easy way to do this?
>
> Thank you!
>
>
>
>
> ________________________________________________________
>
> Christoph Heibl
>
> PhD student
>
> 'Phylogenetics and phylogeography of endemic Atacama Desert flora'
>
> Systematic Botany
> Ludwig-Maximilians-Universität München
> Menzinger Str. 67
> D-80638 München
> GERMANY
>
> phone: +49-(0)89-17861-251
> e-mail: heibl@lmu.de
>
>
>



R-help@stat.math.ethz.ch 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 Wed Jan 10 20:50:04 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Wed 10 Jan 2007 - 10:30:25 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.