TransWikia.com

Warning message when using read.zoo function in R

Geographic Information Systems Asked on October 4, 2021

I have dataset (ndvi_bfast) that contains index daily mean covering about 998 days (2002-2020) . It looks like:

 date    mean
     <dbl>   <dbl>
1 20020112  0.471 
2 20020112  0.483 
3 20020112  0.333 
4 20020121 -0.0928
5 20020121  0.209 
6 20020121  0.0927

I am trying to convert the data frame into zoo object using read.zoo(ndvi_bfast) (read.zoo is a function in zoo package).

z<-read.zoo(ndvi_bfast,format = "%Y-%m-%d",tz="", FUN=NULL, regular = FALSE)

However it gives me the following error:

In zoo(ndvi_bfast, order.by = timeIndex) :
  some methods for “zoo” objects do not work if the index entries in ‘order.by’ are not unique.

How can i solve this problem?

One Answer

read.zoo does create the object. However some zoo methods do not work properly when there are more than one value per date. You can remove duplicate dates by averaging or by using the last observation or whatever that fits you.

# remove duplicated indexes by averaging
ndvi_bfast_mean<-aggregate(ndvi_bfast$mean, list(ndvi_bfast$date), mean)

# remove duplicated indexes by using the last observation
ndvi_bfast_last<-aggregate(ndvi_bfast$mean, list(ndvi_bfast$date), tail, 1)

Then, you can apply read.zoo

z<-read.zoo(ndvi_bfast_mean,format = "%Y-%m-%d",tz="", FUN=NULL, regular = FALSE)

Correct answer by HMSP on October 4, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP