[R] how to assign a value?

Jinsong Zhao jszhao at yeah.net
Sun Dec 11 16:27:59 CET 2011

Hi there,

I hope to modify values in a vector or matrix in the following code:

for (i in 1:9) {
    assign(paste("a.", i, sep = ""), 1:i)
    get(paste("a.", i, sep = ""))[i] <- i+50

I get the following error message:

Error in get(paste("a.", i, sep = ""))[i] <- i + 50 :
   target of assignment expands to non-language object

I have read the FAQ "How can I turn a string into a variable?", however, 
I don't find a way to deal with:

get(paste("a.", i, sep = ""))[i] <- i+50

Any suggestions? Thanks in advance!


More information about the R-help mailing list