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 |
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" |
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" |
month.name[x] # Create vector of month names # [1] "April" "August" "February"