Get Number of Days in a Certain Month in R (Example Code)
This post illustrates how to get the number of days in a certain month in the R programming language.
Introduction of Example Data
x <- c(as.Date("2022-03-15"), # Create vector of dates as.Date("2024-02-18"), as.Date("2023-09-03")) x # [1] "2022-03-15" "2024-02-18" "2023-09-03" |
x <- c(as.Date("2022-03-15"), # Create vector of dates as.Date("2024-02-18"), as.Date("2023-09-03")) x # [1] "2022-03-15" "2024-02-18" "2023-09-03"
Example: Apply days_in_month() Function of lubridate Package to Find Out the Number of Days of a Date Object
install.packages("lubridate") # Install & load lubridate package library("lubridate") |
install.packages("lubridate") # Install & load lubridate package library("lubridate")
days_in_month(x) # Return days in particular months # Mar Feb Sep # 31 29 30 |
days_in_month(x) # Return days in particular months # Mar Feb Sep # 31 29 30
Related Articles
You may find some related R tutorials on topics such as data inspection, indices, and dates in the following list.