[R] Assigning a successive set of values to newly created variables

arun smartpink111 at yahoo.com
Thu Jan 30 05:45:26 CET 2014

xNew <- x
for(i in 1:4){
 xNew <- xNew+0.5
#[1] TRUE
#[1] TRUE

On Wednesday, January 29, 2014 11:35 PM, arun <smartpink111 at yahoo.com> wrote:
May be this helps:


vec1 <- seq(0.5,2,by=0.5)
for(i in 1:4){

Hi all, I have been trying to figure this one out but I'm at a dead end. I want to write a loop that automatically create a series of values 
based on a previous variable. For example, I can initialize the first 
set of values for a variable "x" as 10 scores from a normal 
distribution. Then, I can create 4 new variables labeled x1, x2, x3, x4 
etc. Now, I want x1 to be the original x + a constant (say .5), x2 to be x1+.5, x3 to be x2+.5 etc. 

What I have so far accomplishes the first step (x1 as x+.5) but I
can't figure out how to index the rest. Any help would be greatly 

for(i in 1:4){ 

p.s. I am trying to do this as a component of a function that 
will be generalized based on user input so the example above is a 
simplified version.

More information about the R-help mailing list