R Extract Month Abbreviations & Names Based On Numeric (2 Examples)

In this R tutorial you’ll learn how to extract month names and abbreviations based on a numeric month vector.

Creation of Exemplifying Data

x <- c(4, 8, 2)                     # Numeric vector in R
x                                   # Show vector in RStudio
# [1] 4 8 2

Example 1: Subset month.abb Object in R

month.abb[x]                        # Create vector of month abbreviations
# [1] "Apr" "Aug" "Feb"

Example 2: Subset month.name Object in R

month.name[x]                       # Create vector of month names
# [1] "April"    "August"   "February"

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

Menu
Top