You can use the lubridate
package to get the first day of a week as a date in R. The floor_date
function can be used to round a given date down to the nearest specified time unit, which can be set to "week". Here's an example code:
main.r188 chars11 lines
This code will output the first day of the week containing the input date, which in this example is "2021-05-16". You can change the input date and check that the first_day variable gets updated accordingly.
gistlibby LogSnag