Re: [R] how to automatically create objects with names from a string list?

From: Simon Blomberg <s.blomberg1_at_uq.edu.au>
Date: Wed, 04 Jun 2008 16:10:02 +1000

Or with mapply

name <- c("foo", "bar", "baz")
val <- 1:3
mapply(assign, name, val, pos=1)

Cheers,

Simon.

On Tue, 2008-06-03 at 22:24 -0700, Moshe Olshansky wrote:
> You can use either assign or eval.
>
> Something like
>
> > name <- c("foo", "bar", "baz")
> > for (i in 1:length(name)) assign(name[i],i)
>
>
>
> --- On Wed, 4/6/08, Mark Farnell <mark.farnell_at_gmail.com> wrote:
>
> > From: Mark Farnell <mark.farnell_at_gmail.com>
> > Subject: [R] how to automatically create objects with names from a string list?
> > To: R-help_at_r-project.org
> > Received: Wednesday, 4 June, 2008, 3:15 PM
> > Suppose I have a string of objects names:
> >
> > name <- c("foo", "bar",
> > "baz")
> >
> > and I would like to use a for loop to automatically create
> > three
> > objects called "foo", "bar" and
> > "baz" accordingly. Then how can this
> > be done" (so that in the workspace, foo = 1, bar = 2
> > and baz=3)
> >
> > for (i in name) {
> > .....
> > }
> >
> > Thanks!
> >
> > Mark
> >
> > ______________________________________________
> > 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.

-- 
Simon Blomberg, BSc (Hons), PhD, MAppStat. 
Lecturer and Consultant Statistician 
Faculty of Biological and Chemical Sciences 
The University of Queensland 
St. Lucia Queensland 4072 
Australia
Room 320 Goddard Building (8)
T: +61 7 3365 2506
http://www.uq.edu.au/~uqsblomb
email: S.Blomberg1_at_uq.edu.au

Policies:
1.  I will NOT analyse your data for you.
2.  Your deadline is your problem.

The combination of some data and an aching desire for 
an answer does not ensure that a reasonable answer can 
be extracted from a given body of data. - John Tukey.

______________________________________________
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 Wed 04 Jun 2008 - 06:14:58 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 Wed 04 Jun 2008 - 07:30:41 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