Calculating the daily sums for multiple columns in xts files

Hello,
I have an xts file with 6000 columns and 50000 rows containing hourly values of precipitation. I try to calculate the sum of the daily precipitation on each column however the colSums function doesnt work for xts objects. Even when I tranform my xts file into numeric, I still get an error

p_79_84 is my xts file`
days1 are my daily endpoints

sum_79_84<-period.apply(p_79_84, days1, colSums)

p79_84<-coredata(p_79_84)
p79_84<-p79_84[,2:5786]
p79<-as.data.frame(as.numeric(p79_84))

sum_79_84<-period.apply(p79, days1, colSums)

Any help or idea is highly appreciated

Could you please turn this into a minimal REPRoducible EXample (reprex) including sample data on a copy/paste friendly format? A reprex makes it much easier for others to understand your issue and figure out how to help.

You are right, I'll try to be more specific

Thats the code I used:

library(zoo)
library(xts)
library(timeSeries)

days1<-endpoints(p_79_84,"days")
sum_79_84<-period.apply(p_79_84, days1, colSums)

And thats a sample of the xts file I used (I show only the first 5 columns and rows)

1979-01-01 07:00:00 || 8 || 9 || 1 || 1
1979-01-01 08:00:00 || 8 || 1 || 1 || 1
1979-01-01 09:00:00 || 3 || 3 || 3 || 2
1979-01-01 10:00:00 || 3 || 3 || 6 || 9
1979-01-01 11:00:00 || 2 || 1 || 1 || 2

Sorry if my depiction of the data and the code isn't very detailed, I'm new to this site and still try to figure out how it works

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.