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

Dimitri Liakhovitski dimitri.liakhovitski at gmail.com
Fri Jul 23 19:50:53 CEST 2010


I am expecting to see the week names as row labels of z and the
corresponding values (like in the "monthly" example). I am pretty sure
- in order to get it one needs to install the latest version of zoo.
I've done it just a couple of days ago.
I am getting the error - and nothing is produced. Can it have to do
with the fact that I am using the newer version of zoo?
Again, my full code for that OrigData.csv file I sent is:

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

'data.frame':   440 obs. of  3 variables:
 $ Brand: Factor w/ 11 levels " Plus","agrow",..: 2 2 2 2 2 2 2 2 2 2 ...
 $ Month:Class 'Date'  num [1:440] 18262 18293 18322 18353 18383 ...
 $ Value: int  NA NA NA 100 100 100 100 100 100 99 ...

library(zoo)
z <- read.zoo(OrigData, index.column = 2, split = "Brand")

Error in merge.zoo(` Plus` = c(NA, 98L, 95L, 97L, NA, 98L, 97L, 98L, NA,  :
  series cannot be merged with non-unique index entries in a series
In addition: There were 11 warnings (use warnings() to see them)

warnings()
Warning messages:
1: In zoo(rval4[[i]], ix[[i]]) :
  some methods for “zoo” objects do not work if the index entries in
‘order.by’ are not unique
2: In zoo(rval4[[i]], ix[[i]]) :
  some methods for “zoo” objects do not work if the index entries in
‘order.by’ are not unique
3: In zoo(rval4[[i]], ix[[i]]) :
etc.

But it does not give me this error for my Monthly example - even when
I introduce a few NAs there.


And I get this message:
Error in merge.zoo(` Plus` = c(NA, 98L, 95L, 97L, NA, 98L, 97L, 98L, NA,  :
  series cannot be merged with non-unique index entries in a series
In addition: There were 11 warnings (use warnings() to see them)


On Fri, Jul 23, 2010 at 1:41 PM, David Winsemius <dwinsemius at comcast.net> wrote:
>
> On Jul 23, 2010, at 1:39 PM, Dimitri Liakhovitski wrote:
>
>> Very sorry - I mistunderstood and confused split with index.column -
>> totally my fault.
>> Ok, now I've run this line:
>>
>> z <- read.zoo(OrigData, index.column = 2, split = "Brand")
>>
>> And I am getting:
>> Error in merge.zoo(` Plus` = c(NA, 98L, 95L, 97L, NA, 98L, 97L, 98L, NA,
>>  :
>>  series cannot be merged with non-unique index entries in a series
>> In addition: There were 11 warnings (use warnings() to see them)
>
> I got the warnings but no error:
>
>> z <- read.zoo(OrigData, split = "Brand", index.column=2)
> There were 11 warnings (use warnings() to see them)
>> z
>       Plus agrow chool gress Grib inKid kid omis plet pro romil
>  [1,]    NA    NA    NA    NA   NA    NA  NA   NA   NA  NA    NA
>  [2,]    98    99    98    97   96    96 100   97   97  99    96
>  [3,]    95   100    97    99   92    97 100   97   99 100    99
>  [4,]    97    99    94    98   91    95  99   98   98  99    95
>  [5,]    NA    NA    NA    NA   NA    NA  NA   NA   NA  NA    NA
>  [6,]    98    99    98    97   93    96  99   97   98  99    96
>  [7,]    97   100    98    98   95    96  99   98   98 100    97
>  [8,]    98    99    94    99   96    96  99   98   98  99    97
>  [9,]    NA    NA    NA    NA   NA    NA  NA   NA   NA  NA    NA
> [10,]    98    99    98    98   95    96  99   98   98  99    97
> [11,]    98    99    98    99   97    96  99   98   97  99    99
> [12,]    97   100    96    99   95    95  99   99   97 100    96
> [13,]    96   100    96    96   93     0 100   96   97 100    96
> [14,]    98    99    98   100   94    96 100   98   97  99    99
> [15,]    95   100    98    99   93    95  99   99   99  99    99
> [16,]    97    99    96    99   94    95  98   98   90  99    95
> [17,]    97   100    97    96   92     0 100   96   98 100    95
> [18,]    96    99    98    98   96    97 100   98   99  98    98
> [19,]    98   100    98    98   96    97  99   98   99  99    98
> [20,]    98   100    97    96   95     0 100   96   98  99    96
> [21,]    94   100    98    99   92    97  99   98   98  98    98
> [22,]    98    99    98    97   96    96  99   97   98  99    97
> [23,]    97   100    96    96   93     0 100   95   97 100    95
> [24,]    97   100    98    97   93    96  99   97   98  97    95
> [25,]    98   100    96    97   96    94 100   97   99  99    96
> [26,]    98   100    98    96   95     0 100   96   98  99    95
> [27,]    98   100    98    97   93    96  96   97   98  99    99
> [28,]    99   100    98    98   92    96 100   98   99  99    97
> [29,]    98   100    97    95   95     0 100   95   98  99    95
> [30,]    99   100    98   100   98    98  99  100   99 100    99
> [31,]    97    99    94    97   95    95  99   97   98  98    94
> [32,]    98    99    98    96   95     3 100   96   97  99    96
> [33,]    97    99    98    99   97    97  99   99   99  99    99
> [34,]    96    99    95    96   94    94  98   96   96  98    93
> [35,]    98    99    98    97   94    54 100   97   97  99    96
> [36,]    95   100    97    99   95    95  99   99   98 100    99
> [37,]    98    99    98    98   95    96  99   98   99  99    97
> [38,]    98    99    98    97   96    94 100   97   97  98    96
> [39,]    95   100    98   100   95    97 100   99   99 100    99
> [40,]    97   100    95    98   93    96  99   98   98  99    96
>
> Since you didn't say what was expected, I am not in a position to know if
> this is success.
>
>>
>> And under warnings() it says:
>> 1: In zoo(rval4[[i]], ix[[i]]) :
>>  some methods for “zoo” objects do not work if the index entries in
>> ‘order.by’ are not unique
>>
>>
>>
>> On Fri, Jul 23, 2010 at 1:13 PM, David Winsemius <dwinsemius at comcast.net>
>> wrote:
>>>
>>> But, but, but.... Did you read my message about the need to correctly
>>> specify index columns?
>>>
>>>
>>> The problem is that read.zoo is reading your first column as an index and
>>> it's actually the second column that should be used for that purpose.
>>> --
>>> David.
>>>
>>> On Jul 23, 2010, at 1:01 PM, Dimitri Liakhovitski wrote:
>>>
>>>> Strange, I did attach. Attaching again. Maybe the file just doesn't go
>>>> through?
>>>> I have:
>>>>
>>>> names(OrigData):
>>>> [1] "Brand" "Month" "Value"
>>>>
>>>> I read ?read.zoo
>>>> According to that index should be the column number.
>>>> I thought it should be split = 1 in my case - because I am splitting by
>>>> Brand.
>>>> But neither split = 1 nor split =2 work.
>>>> And split ="Brand" does not work either. Why?
>>>>
>>>> D.
>>>>
>>>> On Fri, Jul 23, 2010 at 12:52 PM, David Winsemius
>>>> <dwinsemius at comcast.net> wrote:
>>>>>
>>>>> ?read.zoo
>>>>>
>>>>> You didn't specify the index column correctly.
>>>>> On Jul 23, 2010, at 12:36 PM, Dimitri Liakhovitski wrote:
>>>>>
>>>>>> 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
>>>>>
>>>>> ?read.zoo
>>>>>
>>>>> You didn't specify the index column correctly. In this case it needs to
>>>>> be =
>>>>> 2.
>>>>>
>>>>>>
>>>>>> 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.
>>>>>>
>>>>> No. Not  attached.
>>>>>
>>>>> --
>>>>>
>>>>> David Winsemius, MD
>>>>> West Hartford, CT
>>>>>
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> Dimitri Liakhovitski
>>>> Ninah Consulting
>>>> www.ninah.com
>>>> <OrigData.csv>
>>>
>>> David Winsemius, MD
>>> West Hartford, CT
>>>
>>>
>>
>>
>>
>> --
>> Dimitri Liakhovitski
>> Ninah Consulting
>> www.ninah.com
>
> David Winsemius, MD
> West Hartford, CT
>
>



-- 
Dimitri Liakhovitski
Ninah Consulting
www.ninah.com



More information about the R-help mailing list