[R] including a variable in another variable name

Erik Iverson iverson at biostat.wisc.edu
Wed Apr 2 22:31:14 CEST 2008

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.

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
> 	[[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