How to use lubridate package In R Language
Lubridate package in R is used to work with date and time objects. It makes it easier to parse and manipulate the objects and needs to be installed and loaded into the working space by the following command :
install.packages("lubridate")
The ymd() method can be used to convert a character date to a date format consisting of year-month-date using the lubridate package. This is followed by the application of seq() method of base R.
Example: Creating a range of dates
R
library ( "lubridate" ) # defining start date start_date <- ymd ( "2021/08/04" ) # defining end date end_date <- ymd ( "2021/08/11" ) # generating range of dates range <- seq (start_date, end_date, "days" ) print (range) |
Output
[1] “2021-08-04” “2021-08-05” “2021-08-06” “2021-08-07” “2021-08-08”
[6] “2021-08-09” “2021-08-10” “2021-08-11”
How to Create a Range of Dates in R
R programming language makes it extremely easy to generate range of integers as well as singular characters. It is also possible to store Date objects in R in different formats and increment the sequentially to produce a range using both base packages as well external ones.
This article discusses various ways by which a range of dates can be defined.