syntax for a loop
Create lagged vectors: # corresponds to x.dif[i-1] lag.minus1 <- c(NA,x.dif[-length(x.dif)]) # corresponds to x.dif[i+2] lag.plus2 <- c(x.dif[-c(1,2)],NA,NA) Then create a true/false vector: selected.rows <- lag.minus1 <= 0 && x.dif > 0 && lag.plus2 > 0 Those indices you want will then have TRUE values. To see row positions in x.dif, use the command (1:length(x.dif))[selected.rows] ---------- Original Message ---------------------------------- From: ebashi <arshia22@yahoo.com> Date: Sun, 28 Nov 2004 03:20:22 -0800 (PST)
I'll appreciate if some one can help me with the following loop. This is the logic of the loop, if we have the following data;
x.df
x.dif . . . . 102 0.00 103 0.42 104 0.08 105 0.00 106 0.00 107 0.00 108 -0.16 109 -0.34 110 0.00 111 -0.17 112 -0.33 113 0.00 114 0.00 115 0.00 116 0.33 117 0.17 118 0.00 . . . . I'm trying to find i's where for (i in 2:length(x.dif)) if (x.dif[i-1]<=0 and x.dif[i]>0 and x.dif[i+2]>0) it would return i+2 to me, How can I turn this to a right format as a loop.(I can't figure out the syntax) Cheers, Sean
_______________________________________________ R-sig-finance@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance