Re: [R] including a variable in another variable name

From: Erik Iverson <iverson_at_biostat.wisc.edu>
Date: Wed, 02 Apr 2008 15:31:14 -0500

You'll want to use paste within the function "assign".

However, consider using a list object to store this data to avoid clutter (both in your workspace and head) and make subsequent data analysis function calls easier.

Best,
Erik Iverson

Georg Ehret wrote:
> Dear R community, I wish to include a variable (e.g. slice of "a" below)
> in another variable's name. My objective would be to get a variable-name
> "data_A" and so on. How can I do this?
>

>> a<-LETTERS[1:25]
>> a

> [1] "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M" "N" "O" "P" "Q" "R"
> "S" "T" "U" "V" "W" "X" "Y"
>> paste("data_",a[1])<-c(1,2,3)

> Error in paste("data", a[1]) <- c(1, 2, 3) :
> target of assignment expands to non-language object
>
>
>
> Thank you and wishing you an excellent day!
> Georg.
> **********************
> Georg Ehret
> Johns Hopkins
> Baltimore, MD
> USA
>
> [[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 Wed 02 Apr 2008 - 20:33:18 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 02 Apr 2008 - 21:30:27 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