Re: [R] Loops and vector operations

2011-12-30 Thread Mago84
Thanks a lot, it was very helpful, I did something like that: EV <- ifelse(sprd > mediaSDP & sprd_d <= mediaSDP_d, -1, 0) SV <- ifelse(sprd > media & sprd_d <= media_d, -17, 0) EC <- ifelse(sprd < mediaSDN & sprd_d >= mediaSDN_d,1,0) SC <- ifelse(sprd < media & sprd_d >= media_d,17,0) in order t

Re: [R] Loops and vector operations

2011-12-28 Thread R. Michael Weylandt
Look at ?ifelse. You'll need to nest them however. If you are feeling a little more ambitious this can be done with ?switch, but for clarity, I'd rather see pre-allocation followed by assignments Something along this pattern: out <- numeric(50) x <- sample(3, 50, TRUE) out[x==3] <- "A" out[x==2

[R] Loops and vector operations

2011-12-28 Thread Mago84
Dear all, this is my first post and I´m very new at R, I don´t know if somebody can help with an issue. I´m doing some exercices and I don´t know if for example I can convert this for in an operation with vectors: for (i in 2:n){ if (ES[i-1]==0 && sprd[i-1]>mediaSDP[i-1] && sprd[i]<=medi