0

Possible Duplicate:
R: How to convert string to variable name?

If I do:

'a' = c(1:10)        
a
[1]  1  2  3  4  5  6  7  8  9 10

here I assign a vector to a string (variable) but i need to a do something like:

a = 'c10'

and then

a = c(1:10)

but the last a must to be c10

How can i do it?

Community
  • 1
  • 1
Dail
  • 4,622
  • 16
  • 74
  • 109
  • 2
    See `get`, `assign`, and http://stackoverflow.com/questions/2679193/how-to-name-variables-on-the-fly-in-r , http://stackoverflow.com/questions/6034655/r-how-to-convert-string-to-variable-name – Ben Bolker Mar 14 '12 at 14:01
  • Also FAQ on R 7.21 http://cran.r-project.org/doc/FAQ/R-FAQ.html#How-can-I-turn-a-string-into-a-variable_003f – Richie Cotton Mar 14 '12 at 14:38

1 Answers1

1

Not sure what you're looking for but your first assignment doesn't need the c() and doesn't need quotes around the a.

a <- 1:10

if you want the last entry to be the string 'c10', you can get there a few different ways.

a <- c(1:9,'c10')

or

a <- 1:10
a[10] <- 'c10'

Or if Ben Bolker is on the right track:

a <- 'c10'
assign(a,1:10)
Justin
  • 42,475
  • 9
  • 93
  • 111