[R] For loop with if else statement

2007-09-05 Thread Monica Pisica
Hans, I think your problem is that you don't use the variable which takes different values in your if statement your "i" changes values and has really nothing to do with your x variable (except the length part ). Also all the other variables need to be declared somehow - otherwise ho

Re: [R] For loop with if else statement

2007-09-04 Thread Duncan Murdoch
On 9/4/2007 9:59 AM, Hans Ole Ørka wrote: > Hi, > I try to make a simple for loop with a if else statement (First example - > Below) and extend it to a more complex loop (Second example). However, my > results > > #First example: > x=c(1,2) > t=for(i in 1:length(x)){ > if (x==1){a=x+1}else > if

[R] For loop with if else statement

2007-09-04 Thread Hans Ole Ørka
Hi, I try to make a simple for loop with a if else statement (First example - Below) and extend it to a more complex loop (Second example). However, my results #First example: x=c(1,2) t=for(i in 1:length(x)){ if (x==1){a=x+1}else if (x==2){a=x} } Returned from R: Warning messages: 1: the condi