R Basic

R month.abb

The month.abb is a built-in R constant, a three-letter abbreviation for the English month names.

Example 1: Basic usage

month.abb

Output

[1] "Jan" "Feb" "Mar" "Apr" "May" "Jun" "Jul" "Aug" "Sep" "Oct" "Nov" "Dec"
Figure: Visual Representation of month.abb

Example 2: Changing abbreviations to numerical month values

If you have a vector of integers consisting of the number of the month, then you can use it to get the three-letter abbreviation of the month name by doing the following.

mnth <- c(12, 10, 8, 6, 4, 2)
month.abb[mnth]

Output

[1] "Dec" "Oct" "Aug" "Jun" "Apr" "Feb"

Recent Posts

R dplyr::slice() Function

The dplyr::slice() function subsets rows by their position or index within a data frame. If…

1 day ago

How to Create an Empty Vector and Append Values in R

R vectors are atomic, which means they have homogeneous data types. They are contiguous in…

2 days ago

How to Remove Single and Multiple Columns from Data Frame in R

DataFrames are like tables that contain rows and columns. Each column can have a different…

3 days ago

How to Convert Date to Numeric in R

Dates in R are stored as the number of days since 1970-01-01, so converting a…

4 days ago

How to Create a Data Frame from Vectors in R

In R, you can think of a vector as a series of values in a…

2 weeks ago

R dplyr::filter() Function: Complete Guide

The dplyr filter() function in R subsets a data frame and retains all rows that…

2 weeks ago