I have some daily time-series data that i need to extract the ‘week day percent’ relative to the week mean. For example, if the first week has mean = 100 and the Sunday value for this week is 20, then sunday becomes 0.2.
Here’s some random data:
set.seed(0)
y = rnorm(1705)
date = seq(as.Date('2008-01-01'), by = 'day', length = length(y))
data.df = data.frame(y, date)
I need a new column called pecent, which is the value explained above. I tried to add some
columns then use tapply, but failed. Appreciate any help!
First create a
weekvariable usingformat. Then useddplyandtransform.Note that week 00 usually is not a full week as is the last week of the year. Merge last and first weeks of subsequent years if that matters.