Re: [R] variable name question

2011-10-09 Thread Deepankar Basu
Thanks for both comments. Indeed the sep = "" is needed. On Sun, Oct 9, 2011 at 9:43 PM, Rolf Turner wrote: > On 10/10/11 04:53, R. Michael Weylandt wrote: > > > > Try this: >> >> for (i in 1990:2009) { >> varName = paste("pci", i, collapse = "") >> assign(varName, log(get(varName)) >>

Re: [R] variable name question

2011-10-09 Thread Rolf Turner
On 10/10/11 04:53, R. Michael Weylandt wrote: Try this: for (i in 1990:2009) { varName = paste("pci", i, collapse = "") assign(varName, log(get(varName)) } I believe that ``sep= " '' is needed here rather than collapse. Try: paste("junk",42,collapse="") You get [1]

Re: [R] variable name question

2011-10-09 Thread David Winsemius
On Oct 9, 2011, at 2:24 PM, Carlos Ortega wrote: Hello, In R you just need to take the log of the whole whole data.frame where you have your pci* and store in a new variable. You do not need to use a "for" loop: log.df <- log(your_data_frame) Possibly with a selection for the column name

Re: [R] variable name question

2011-10-09 Thread Carlos Ortega
Hello, In R you just need to take the log of the whole whole data.frame where you have your pci* and store in a new variable. You do not need to use a "for" loop: log.df <- log(your_data_frame) Regards, Carlos Ortega www.qualityexcellence.es On Sun, Oct 9, 2011 at 5:34 PM, deepankar wrote: >

[R] variable name question

2011-10-09 Thread deepankar
Hi All, This is surely an easy question but somehow I am not being able to get it. I am using R 2.13.2 and have a data set where variable names like this appear: pci1990, pci1991, ... , pci2009. "pci1990" has data on per capita income for 1990, "pci1991" has data on per capita income for 19

Re: [R] variable name question

2011-10-09 Thread R. Michael Weylandt
"This is surely an easy question but somehow I am not being able to get it." get() is the key -- it takes a string and returns the object with that string as its name. Assign() goes the other way Try this: for (i in 1990:2009) { varName = paste("pci", i, collapse = "") assign(varName, lo

[R] variable name question

2011-10-09 Thread Deepankar Basu
Hi All, This is surely an easy question but somehow I am not being able to get it. I am using R 2.13.2 and have a data set where variable names like this appear: pci1990, pci1991, ... , pci2009. "pci1990" has data on per capita income for 1990, "pci1991" has data on per capita income for 1991,