R: Aggregation by dates with POSIXct?

I have a number of zoos that use the POSIXct index.

To aggregate by day, I tried these two ways:

aggregate(myzoo,format((index((myzoo)),"%Y-%m-%d")),sum)

aggregate(myzoo,as.Date(index(myzoo)),sum)

I do not know why they do not give the same result. Weekend has been removed from myzoo series. The as.Date method looks fine, but the format aggregation gives me data on the weekend.

Why?

Which one is correct?

I even tried it as.POSIXct(format(...))

+3
source share
1 answer

, , , . - , , apply.daily xts:

apply.daily(myzoo, sum)

:

> x <-  zoo(2:20, as.POSIXct("2003-02-01") + (2:20) * 7200)
> apply.daily(x, sum)
> 2003-02-01 22:00:00 2003-02-02 16:00:00 
                 65                 144 
+2

Source: https://habr.com/ru/post/1773853/


All Articles