#generate time sequence
time <- seq.Date(from = as.Date("2002/01/01",format = "%Y/%m/%d"), by = "week", length.out = 679)
tail(time)
#transfer time sequence to matrix
time=matrix(time,nrow = length(time),ncol = 1)
dim(time)
slope3_1=matrix(NA,nrow=679,ncol=439) #679weeks, 439firms
for(i in 1:439){
stock=read.csv(paste("E:/CDS_data/stock_1/stock.", i,".csv", sep=""),header=T,stringsAsFactors=F,fill=TRUE)
stock=select(stock,firms,date,slope3)
stock[,"date"]=as.Date(stock[,"date"],form="%Y-%m-%d")
tseq=as.character(time)
tseq=as.Date(time,form="%Y/%m/%d")
for(j in 1:679){
if(stock[j,"date"]>=tseq[length(tseq)]){
slope3_1[length(tseq),i]=stock[j,"slope3"]
next
}
for(k in 1:678){
if((stock[j,"date"]>=tseq[k])&(stock[j,"date"]<tseq[k+1])){
slope3_1[k,i]=stock[j,"slope3"]
break
}
}
}
}
Error in if (stock[j, "date"] >= tseq[length(tseq)]) { :
missing value where TRUE/FALSE needed


雷达卡




京公网安备 11010802022788号







