in R, the arguments of "for loop"
Posted
by alex
on Stack Overflow
See other posts from Stack Overflow
or by alex
Published on 2010-04-18T13:25:01Z
Indexed on
2010/04/18
13:33 UTC
Read the original article
Hit count: 252
Filed under:
r
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.
© Stack Overflow or respective owner