time series - R growth rate calculation week over week on daily timeseries data -
i'm trying calculate w/w growth rates entirely in r. use excel, or preprocess ruby, that's not point.
data.frame example
date gpv type 1 2013-04-01 12900 office 2 2013-04-02 16232 office 3 2013-04-03 10035 office
i want factored 'type' , need wrap date type column weeks. , calculate week on week growth.
i think need ddply group week - custom function determines if date in given week or not?
then, after that, use diff
, find growth b/w weeks divided previous week.
then i'll plot week/week growths, or use data.frame export it.
this closed had same useful ideas.
update: answer ggplot:
all same below, use instead of plot
ggplot(data.frame(week=seq(length(gr)), gr), aes(x=week,y=gr*100)) + geom_point() + geom_smooth(method='loess') + coord_cartesian(xlim = c(.95, 10.05)) + scale_x_discrete() + ggtitle('week on week growth rate, apr 1') + ylab('growth rate %')
(old, correct answer using plot)
well, think it:
df_net <- ddply(df_all, .(date), summarise, gpv=sum(gpv)) # df_all has daily data. df_net$week_num <- strftime(df_net$date, "%u") #get week # 'group by' in ddply df_weekly <- ddply(df_net, .(week_num), summarize, gpv=sum(gov)) gr <- diff(df_weekly$gpv)/df_weekly$gpv[-length(df_weekly$gpv)] #seems correct, don't understand via: http://stackoverflow.com/questions/15356121/how-to-identify-the-virality-growth-rate-in-time-series-data-using-r plot(gr, type='l', xlab='week #', ylab='growth rate percent', main='week/week growth rate')
any better solutions out there?
Comments
Post a Comment