deaR useRs,

I am trying to assign different values to different objects in a for loop.
The following is a toy example of the part that has been giving me a hard
time.

The first "for loop" generates four objects, b0, b1, b2, b3 with random
numbers.
And, the second "for loop" is equivalent to
b1 = b0
b2 = b1
b3 = b2
b4 = b3

But, when I run this code, the result is equivalent to
b1 = b0
b2 = b0
b3 = b0
b4 = b0

So, the increment does not seem to be properly working for the second part
of the "assign" function.
Why would this be?

for (i in 0:3)
       {
           r = runif(1)
           assign(paste('b',i,sep=''),r)
       }


for (i in 1:4)
       {

assign(paste('b',i,sep=''),eval(parse(text=paste('b',i-1,sep=''))))
       }

Thank you.

Nic

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to