R-incorrect number of dimensions

2716 views r
-1

This is part of my code.

read.bossa.data<-function(vec.names){
  p<-length(vec.names)
  n1<-12000
  dates<-matrix(0,p,n1)
  closes<-matrix(0,p,n1)
  max.n2<-0

  for(i in 1:p){
    filename<-paste("E:/mstzgr/",vec.names[i],".mst",sep="")
    tmp<-scan(filename,list(NULL,date=numeric(),NULL,NULL,NULL,close=numeric(),NULL),skip=1,sep=",")
    n2<-length(tmp$date)
    max.n2<-max(n2,max.n2)
    dates[i,1:n2]<-tmp$date
    closes[i,1:n2]<-tmp$close
  }
  dates<-dates[,1:max.n2]
  closes<-dates[,1:max.n2]

The error is Error in dates[1:p, 1:max.n2] : incorrect number of dimensions

answered question

Please complete your code, it is not correct as-is.

1 Answer

9

It could be that dates has become a list because you are populating with tmp$scan and tmp$close. What does class(dates) say? If it is still a matrix, dim(dates) should not be what you expect.

length(vec.names) could also be causing this.

posted this

Have an answer?

JD

Please login first before posting an answer.