I am trying to solve an introductory statistics textbook exercise on time series using R. The data was given as daily sales from Monday to Friday for three weeks. No date was given. My brave attempt is just give a fictitious starting date (which is a Sunday, the beginning of a week) and set it as the start time for my concocted time series, and assign NA to sales on Saturday and Sunday. Then I find the raw time series using xts() and moving-average time series (of order 5) using forecast::ma(). The raw time series appeared fine but the timestamps of the moving-average was not, which was a sequence of 1 to 15. (The plot of the moving-averages by itself seemed fine with time as 1 to 15). How can I preserve the timestamps of the ma time series to date as in the raw time series?

The code of my attempt is as follows:

daysales <- c(NA, 140, 150, 100, 150, 220, NA,

NA, 155, 170, 105, 220, 300, NA,

NA, 175, 190, 130, 225, 325, NA)

day <- seq(as.Date("2024/1/7"), # 2024/1/7 is a Sunday

length = 21,

by = "day")

daysales_xts <- xts(daysales, day)

daysales_xts <- daysales_xts[.indexwday(daysales_xts) %in% 1:5]

forecast::ma(daysales_xts, 5)

Because of the different timestamps in the raw and ma time series, I can't plot them together on the same graph using {ggplot2}.

I'm at the end of my wits ;).