To create a sequence of dates in R you can use the as.Date() function along with seq() function. Following are some examples. While your needs may be different, this will help you get started.
1. Creating a sequence of dates by specifying the start date and number of days
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Start date: January 5, 2011. Number of days: 45 | |
dates <- seq(as.Date("2011-01-05"), by=1, len=45) |
2. Creating a sequence of dates by specifying the start date and an end date
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Start date: January 5, 2011. End date: March 15, 2011 | |
dates <- seq(as.Date("2011-01-05"), as.Date("2011-03-15"), by=1) |
No comments:
Post a Comment