make an intra-month sum of xts object - r

i have an xts object
It's a daily time series.
With endpoints(prices, 'months') i can have the position of the start and the end of every months
What i want is an xts object where every data is the sum of the daily data in every month
Which is the most efficient way to do this?

Related

How to convert a weekly dataset into a time series in R

i have a WEEKLY dataset that start on 1986.01.03 and end on 2022-10-07.
The problem is when I forecast the time series with Arima +garch, because the date in T0 is wrong, i.e. 1975 enter image description here.
The function that I used to convert the dataset into time series is here, but I think that the problem is here, since it doesn't take on the right date.
FutureWeekly= ts(WeeklyFuture$FutureWeekly, start= c(1986,1), end = c(2022,10), frequency = 52)
does anyone know how to convert a weekly dataset to time series other than this?
There are the first rows of my dataset and then I have to transform that into returns (diff(log(FutureWeekly) to do the ARMA+GARCH
enter image description here
Try this:
futures<-c(WeeklyFuture$FutureWeekly) #convert to vector
FutureWeekly= ts(futures, start= c(1986,1,10), end = c(1986,3,7), frequency = 52) #add day of week ending on
One of the things ts() demands is a vector of values. I think it might also be easier for ts() to convert the data if it was able to see the 7-day increments.
Assuming you have full un-broken weekly data for the entire period, I think these two things will solve the problem.

Time series and how I can construct a ts object

I have a dataset with 3 variables:
the first is date (example"01/01/2019" )
the second is hour (example:"01:00"), and
the third is a numeric.
I want to construct an object ts, but I don't know how I can do this.The first and second variables are characters.
I want an hour time series

Aggregating XTS by Week Commencing Sunday in R

I have a multivariate xts object containing daily time series for different marketing channels (about 4 years worth), and want to aggregate this into weekly data starting on Sunday.
I know I can use the following to get aggregate by weekly
sp_weekly_input <-apply.weekly(sp_xts, function(x){ c(ppc= sum(x$ppc_brand),
tv= sum(x$tv),
radio= sum(x$radio),
display= sum(x$display),
social= sum(x$social))})
But this will default to a Monday start, how can I override this and get a new multivariate xts for weekly channel spends starting on Sundays?

How to Tell R What Day of the week should be the start or end day of the week?

When converting a daily XTS object in R to weekly using to.weekly() function, The weekly XTS object has week-endings on "Sunday". How is it possible to set the week-endings to be on "Saturday" instead?

How to merge a daily and an intra-day XTS object?

I am trying to merge a daily XTS object (indexed by POSIXCT, format = "%d/%m/%Y") with an intraday XTS object (indexed by POSIXCT, format = "%d/%m/%Y %H:%M").
The intra day object doesn't have a midnight (00:00) index, but by default the merge creates one and adds the daily variable to that observation.
How can I merge the daily into the intraday, but merge to the nearest index, so I do not create a bunch of 00:00 observations in my data?
Not sure if its the best solution, but I ended up filtering out any indexes that matched in both data
x <- x[!(index(x) %in% index(y))]

Resources