Re: [R] naming components of a list

From: Duncan Mackay <mackay_at_northnet.com.au>
Date: Mon, 26 May 2008 09:58:52 +1000

If there is a lot of names perhaps sprintf(format, 1:length(L), sep="")

where format is the appropriate format for sprintf so that it is easier to read

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
ARMIDALE NSW 2351
Email dmackay9_at_pobox.une.edu.au
Home mackay_at_northnet.com.au

At 07:11 26/05/2008, you wrote:
>Content-Type: text/plain
>Content-Disposition: inline
>Content-length: 1857
>
>And if you have "thousands of names" like this:
>names(L) <- paste ("names", 1:length(L), sep="")
>
>Nael
>
>On Sun, May 25, 2008 at 10:38 PM, Erin Hodgess <erinm.hodgess_at_gmail.com>
>wrote:
>
> > try this:
> >
> > > names(L) <- c("name1","name2","name3")
> > > L
> > $name1
> > [1] "Fred"
> >
> > $name2
> > [1] "Mary"
> >
> > $name3
> > [1] "SAM"
> >
> > >
> > >
> > HTH,
> > Sincerely,
> > Erin
> >
> >
> > On Sun, May 25, 2008 at 2:42 PM, joseph <jdsandjd_at_yahoo.com> 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"
> > >
> > > Any help will be much appreciated
> > > Joseph
> > >
> > >
> > >
> > > [[alternative HTML version deleted]]
> > >
> > >
> > > ______________________________________________
> > > 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.
> > >
> > >
> >
> >
> >
> > --
> > Erin Hodgess
> > Associate Professor
> > Department of Computer and Mathematical Sciences
> > University of Houston - Downtown
> > mailto: erinm.hodgess_at_gmail.com
> >
> > ______________________________________________
> > 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.
> >
>
> [[alternative HTML version deleted]]
>
>______________________________________________
>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.



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 - 23:56:21 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 Mon 26 May 2008 - 02:30:43 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