Skip to content

Instantly share code, notes, and snippets.

@thoolihan
Created November 8, 2017 16:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thoolihan/06d2d93d2618fd6535ffedaa40f33bff to your computer and use it in GitHub Desktop.
Save thoolihan/06d2d93d2618fd6535ffedaa40f33bff to your computer and use it in GitHub Desktop.
creating week from date
> df <- data.frame(date = c('2017-10-01', '2017-10-11'))
> df$date <- as.Date(df$date)
> df
date
1 2017-10-01
2 2017-10-11
> sapply(df$date, function(d) {if (d < as.Date('2017-10-07')) 1 else 0})
[1] 1 0
> df$week1 <- sapply(df$date, function(d) {if (d < as.Date('2017-10-07')) 1 else 0})
> df
date week1
1 2017-10-01 1
2 2017-10-11 0
>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment