我正在尝试使用以下代码确定日期在矩阵中的位置:
#portret is a list of daily returns for three different stocks from 1980-01-01 to 2010-12
#13.These dates are listed in the first column of the portret data frame
library(quantmod)
library(FRAPO)
getSymbols(c("F","AA","IBM"),from="1980-01-01", to="2010-12-31")
port=cbind(F$F.Adjusted,AA$AA.Adjusted,IBM$IBM.Adjusted)
portret=returnseries(port,"discrete",trim=TRUE)
portret=data.frame(index(portret),coredata=portret)
date.list=seq.Date(as.Date("1990-10-01"),as.Date("2010-10-01"),by="month")
length(date.list)
#this equals 241
date.index=matrix(0,241,2)
for(i in 1:241){
date.index[i,]=which(portret[,1]==as.character(date.list[i]),arr.ind=TRUE)}
我不断收到此错误:替换的长度为零
请指教。