[R] Error produced by read.zoo: "bad entries"

Dimitri Liakhovitski dimitri.liakhovitski at gmail.com
Fri Jul 23 18:36:18 CEST 2010


Hello!

I have a data set similar to the data set "monthly" in the example below:

monthly<-data.frame(month=c(20090301,20090401,20090501,20100301,20100401,20090301,20090401,20090501,20100301,20100401),monthly.value=c(100,200,300,101,201,10,20,30,11,21),market=c("Market
A","Market A", "Market A","Market A", "Market A","Market B", "Market
B","Market B","Market B", "Market B"))
monthly$month<-as.character(monthly$month)
monthly$month<-as.Date(monthly$month,"%Y%m%d")
(monthly)
str(monthly)


I am trying to use read.zoo - like in 3 lines below:
library(zoo)
z <- read.zoo(monthly, split = "market")
(z)

With the artificially produced data set above, it works just fine.
However, with my data it gives me an error:

OrigData<-read.csv("OrigData.csv")
OrigData$Month<-as.character(OrigData$Month)
OrigData$Month<-as.Date(OrigData$Month,"%m/%d/%y")
str(OrigData)

### The result of str(OrigData) is:
'data.frame':   440 obs. of  3 variables:
 $ Brand       : Factor w/ 11 levels "aBrand","bBrand",..:
Month       :Class 'Date'  num [1:440] 13514 13545 13573 13604,...
Value: int  NA NA NA 100 100 100 100 100 100 99

Then I try:
z <- read.zoo(OrigData, split = "Brand")

And get the error:
Error in read.zoo(OrigData, split = "Brand") :
  index has 440 bad entries at data rows: 1 2 3 4 5 6 7 8 9 10 11 12 13

But the structure of my OrigData is exactly the same as of monthly. OK
- OrigData always has a few NAs in "Value" coming first - but that's
consistent for all brands.
Any idea what might be wrong?
Thanks  a lot!

Just in case -attaching the actual file.

Dimitri


More information about the R-help mailing list