Created
March 3, 2020 08:21
-
-
Save DoktorMike/bde61fb4f5d3a1d7dcaa404a2b9f45c7 to your computer and use it in GitHub Desktop.
weekly_to_daily_values
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(ISOweek) | |
library(lubridate) | |
# Load weekly data | |
mydf <- read_csv("weeklydata.csv")[, -1] %>% mutate(week = ISOweek(date)) | |
# Create daily dates | |
firstdate <- min(mydf$date) - 6 | |
lastdate <- max(mydf$date) | |
datedf <- tibble(date = seq(firstdate, lastdate, by = "1 day"), week = ISOweek(date)) | |
# Join the datedf with mydf | |
mydf <- mydf %>% select(-date) | |
mydf <- left_join(datedf, mydf) | |
# Correct values from weekly to daily | |
mydf <- mydf %>% mutate(value = value / 7) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment