Skip to content

Instantly share code, notes, and snippets.

@RamiKrispin
Created May 15, 2021 21:09
Show Gist options
  • Select an option

  • Save RamiKrispin/4817618c62c7e04e8910fc867dcc66cd to your computer and use it in GitHub Desktop.

Select an option

Save RamiKrispin/4817618c62c7e04e8910fc867dcc66cd to your computer and use it in GitHub Desktop.
Example for creating weekly index
df <- data.frame(date = seq.Date(from = as.Date("2020-01-01"),
length.out = 100,
by = "week")) %>%
dplyr::mutate(week_index = 1 + (as.numeric(date) - as.numeric(min(date)))/7)
head(df)
@RamiKrispin
Copy link
Copy Markdown
Author

# Creating data.frame with a date column
df <- data.frame(date = seq.Date(from = as.Date("2020-01-01"), 
                                 length.out = 100, 
                                 by = "week")) 

# Creating weekly index
df$week_index <- (as.numeric(df$date) - as.numeric(min(df$date))) / 7 + 1


head(df)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment