[R] use value in variable to be name of another variable

Matthew mccormack at molbio.mgh.harvard.edu
Mon Jul 11 22:01:32 CEST 2016


I want to get a value that has been assigned to a variable, and then use 
that value to be the name of a variable.

For example,

tTargTFS[1,1]
# returns:
                 V1
"AT1G01010"

Now, I want to make AT1G01010 the name of a variable:
AT1G01010 <- tTargTFS[-1,1]

Then, go to the next tTargTFS[1,2]. Which produces
                V1
"AT1G01030"
And then,
AT1G01030 <- tTargTFS[-1,2]

I want to do this up to tTargTFS[1, 2666], so I want to do this in a 
script and not manually.
tTargTFS is a list of 2: chr [1:265, 1:2666], but I also have the data 
in a data frame of 265 observations of 2666 variables, if this data 
structure makes things easier.

My initial attempts are not working. Starting with a test data structure 
that is a little simpler I have tried:
for (i in 1:4)
{ ATG <- tTargTFS[1, i]
assign(cat(ATG), tTargTFS[-1, i]) }

Matthew



More information about the R-help mailing list