[R] Loops and vector operations
Mago84
davidquiasmo at gmail.com
Wed Dec 28 17:55:57 CET 2011
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]<=mediaSDP[i]) {ES[i]
<- -1} else
if((ES[i-1]==-1 || ES[i-1]==-15) && sprd[i]>media[i]) {ES[i] <- -15} else
if((ES[i-1]==-1 || ES[i-1]==-15) && sprd[i]<=media[i]) {ES[i] <- -17} else
if(ES[i-1]==0 && sprd[i-1]<mediaSDN[i-1] && sprd[i]>=mediaSDN[i])
{ES[i] <- 1} else
if((ES[i-1]==1 || ES[i-1]==15)&& sprd[i]<media[i]) {ES[i] <- 15} else
if((ES[i-1]==1 || ES[i-1]==15)&& sprd[i]>=media[i]) {ES[i] <- 17}
else {ES[i] <-0}
}
Thanks a lot!!
--
View this message in context: http://r.789695.n4.nabble.com/Loops-and-vector-operations-tp4240434p4240434.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list