[R] naming components of a list

Duncan Mackay mackay at northnet.com.au
Mon May 26 01:58:52 CEST 2008


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.



More information about the R-help mailing list