Here's a code snippet that shows how to get a list of dates for the next 20 Fridays in R using the lubridate
package:
456 chars17 lines
This code will generate a list of the next 20 Fridays, starting from the current date. We use the Sys.Date()
function to get today's date, then use the weekdays()
function to determine the numeric day of the week (0-6, where 0 is Sunday and 6 is Saturday). We calculate the number of days until the next Friday, then use the ceiling()
function to round up to the next whole number of weeks. We add this number of weeks (rounded up to the nearest Friday) to the current date to get the starting date.
We then use the seq()
function to generate a sequence of 20 dates, incrementing by 7 days for each Friday. Finally, we format the dates as strings in the "YYYY-mm-dd" format using the format()
function, and print the list of dates using print()
.
gistlibby LogSnag