in R, the arguments of "for loop"
- by alex
Could anyone please tell me what is wrong with the R code below:
i = 1.001
#make SAV and STO become vector
SAV = c()
STO = c()
#set the initial values for the vector
SAV[1] = 0
STO[1] = 100
for (t in 2:1000) {
if ((price[t]>9.9)&(price[t]<10.1)&(SAV[t-1]!=0))
SAV[t]=SAV[t-1]*i
STO[t]=0
}
for (t in 2:1000) {
if ((price[t]>9.9)&(price[t]<10.1)&(SAV[t-1]=0))
STO[t] = STO [t-1]
SAV[t] = 0
}
SAV
STO
What I am trying to do is to find vector for both SAV and STO.