【发布时间】:2010-04-18 13:25:01
【问题描述】:
谁能告诉我下面的 R 代码有什么问题:
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
我要做的是为 SAV 和 STO 找到向量。
【问题讨论】:
-
if 块周围缺少花括号。
标签: r