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
# [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
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.

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed