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

How to Check If File and Folder Already Exists in R

Whether you are reading or writing files via programs in the file system, it is…

1 day ago

How to Check Data type of a Variable in R

When it comes to checking the data type of a variable, it depends on what…

2 days ago

Mastering grepl() Function in R

The grepl() function (stands for "grep logical") in R searches for patterns within each element…

3 days ago

zip(), unzip() and tar(), untar() Functions in R

The zip() function creates a new zip archive file. You must ensure that the zip tool…

4 days ago

How to Create Directory and File If It doesn’t Exist in R

When working with file systems, checking the directory or file existence is always better before…

5 days ago

How to Create a Grouped Boxplot in R

To create a grouped boxplot in R, we can use the ggplot2 library's aes() and…

7 days ago