I'm trying to read a set of csv datasets into R as zoo time series. I've managed to convert the data into data frames with the index columns as dates and the rest as numeric vectors. I now need to convert these data frame into zoo. Here's the code I'm using:

for(x in 1:length(files)){
    for(n in 1:length(files[[x]]){
        files[[x]][[n]]<-unique(files[[x]][[n]]) #removes duplicate rows
        }
    zfiles[[x]]<-lapply(files[[x]],function(n) read.zoo(n))
    }

Upon running it I get this error: Error in read.zoo(n) : index has bad entry at data row 4

I've tried randomly converting individual datasets within files and i do not get any error, so I'm assuming there are certain problem sets which cause the issue. Is there any way to remove the bad entries before converting to zoo?

Thanks

有帮助吗?

解决方案

Turns out the bad entry rows were rows with NA. Fixed it using complete.cases, as per this link: Remove rows with NAs (missing values) in data.frame

其他提示

make sure your dates column is in the format of a POSIXct, then use

zoo(<vector of numeric>, order.by=<vector of POSIXct>)
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top