Skip to content
Prev 360514 / 398503 Next

Create a new variable and concatenation inside a "for" loop

What's not possible, as far as I know, is to create a variable using an
expression that refers to elements within the variable.

For example, suppose that a some point during my R session, there is no
variable named tmpx:
[1] FALSE

If I try to reference tmpx, in this case by using an extraction operator
Error in tmpx[3] <- 2 : object 'tmpx' not found

it fails. That is, you can't assign to the third element of tmpx when tmpx
doesn't exist, and trying to do so does not automatically create tmpx. As
best as I can tell, this is what you are asking about.

Note that this behavior of the R language has nothing to do with looping
or using a loop index to create a variable, but rather the idea that one
can't reference a non-existant variable.

In this case, I think that the R way of doing things is just different
than the matlab way.


-Don