Skip to content
Prev 273885 / 398506 Next

variable name question

"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, log(get(varName))
}

That said, the standard advice is that its usually more R-ish to keep
all your data in a list, data frame or, for this case, a matrix.

Michael
On Sun, Oct 9, 2011 at 11:46 AM, Deepankar Basu <basu.15 at gmail.com> wrote: