I am new to R and I'm trying to do some time-series analysis for Dogecoin and Dogecoin google searches (google trends) respectively. However, if you load more than 90 days of data for google trends it returns the weekly average search volume. My Dogecoin data, however, is daily. My Dogecoin data, however, is daily. I would like to get my Dogecoin data to be the average for each week (Mo-So). I have been googling on how to do this for about an hour and couldn't figure it out. I have tried SMA with the TTR library, But I don't just want to average 7 consecutive days. I would like to get the average from Monday to Sunday, just like what I have with my google trends data. Could someone help me do that? Should I convert it to a ts first?
0
votes
2 Answers
1
votes
If I had a dput()
example I would be able to test it, but I think this should work:
library(dplyr)
library(lubridate)
library(tidyr)
doge <- doge %>%
mutate(year = year(timestamp), month = month(timestamp), week = week(timestamp)) %>%
unite_("date", c("year", "month", "week"), sep ="-") %>%
group_by(date) %>%
summarise(mean_price_usd = mean(price_usd, na.rm = TRUE))