I'm writing a function that will take my df$date
field (which is daily POSIXct
date (by day) and create a new variable called df$wbm
(wbm = week beginning Monday). I know the math works because I've done this in Excel but the syntax is not working, see below:
df$wbm<- if (weekdays(df$date) == "Sunday") {
df$date - days(6)
} else { df$date + (days(2) - df$date)
}