Wednesday, December 28, 2011

Creating a sequence of dates in R

Creating a sequence of dates in R

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

# 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

# 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