[R] for(variable in [])do

Allan Engelhardt allane at cybaea.com
Thu Aug 13 10:10:14 CEST 2009

On 13/08/09 08:55, Inchallah Yarab wrote:
> [...]
>> for (LRPhase  in c(-1,1))
> + {Phase1<- output[output[,2]==LRPhase,]}
>> Phase1<- Phase1[order (Phase1[,6]),]
>> [...]
> why when i write for LRPhase in c(1,-1), it gives me the result only for Phase = 1??
Because you re-assign the Phase1 variable in the for loop.  At the end 
of the loop it has the value you set during the last iteration, i.e. 
LRPhase==1 since you used c(-1,1) in the code (and not c(1,-1) as in 
your question).


for (LRPhase  in c(-1,1)) {
   Phase1<- output[output[,2]==LRPhase,]
   Phase1<- Phase1[order (Phase1[,6]),]

Hope this helps a little


More information about the R-help mailing list