Get day of month from date in R

In Order to get day of month from date in R we will be using Format() function. Let’s see how to get day of month from date in R with an example.

Let’s first create the dataframe.

### Create Data Frame
df1 = data.frame (
  Name =c('Annie','Catherine','Teresa','Peterson','Richard','joe'),
  Date_of_birth = as.Date(c('1995-06-16','1991-04-19','1993-07-22','1990-03-26','1991-05-12','1992-09-13')))
df1

dataframe df1 will be

get day of month from date in R 1

 

Get day of month from date in R

Day of Month is extracted from Date_of_birth column using Format() functions as shown below.

df1$day_of_month <- as.numeric(format(df1$Date_of_birth,'%d'))
df1

So the resultant data frame has a column day_of_month with day of month extracted from date.

get day of month from date in R 2

 

                                                                                                               

Author

  • Sridhar Venkatachalam

    With close to 10 years on Experience in data science and machine learning Have extensively worked on programming languages like R, Python (Pandas), SAS, Pyspark.