Re: [R] naming the components of a list

From: Rolf Turner <r.turner_at_auckland.ac.nz>
Date: Mon, 26 May 2008 08:21:55 +1200

On 26/05/2008, at 7:54 AM, joseph wrote:

> Hi
> I have a character vector with thousands of names which looks like
> this:
>> V=c("Fred", "Mary", "SAM")
>> V
> [1] "Fred" "Mary" "SAM"
>> class(V)
> [1] "character"
>
> I would like to change it to a list:
>> L=as.list(V)
>> L
> [[1]]
> [1] "Fred"
> [[2]]
> [1] "Mary"
> [[3]]
> [1] "SAM"
>
> but I need to name the components as name1, name2, name3,
>
> so it should look like this:
> $name1
> [1] "Fred"
> $name2
> [1] "Mary"
> $name3
> [1] "SAM"
names(L) <- paste("name",1:3,sep="")

        cheers,

                Rolf Turner

######################################################################
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}

R-help_at_r-project.org 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 Sun 25 May 2008 - 20:24:03 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 25 May 2008 - 20:31:48 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.

list of date sections of archive