-1

If I have date in this format:

date <- c('11.17', '12.17', '01.18')

How do I change it to this format:

'Nov 2017', 'Dec 2017', 'Jan 2018'
John peter
  • 125
  • 7

3 Answers3

1

You could use the yearmon class from zoo package.

library(zoo)
as.yearmon(date, format = "%m.%y")
#[1] "Nov 2017" "Dec 2017" "Jan 2018"
d.b
  • 31,615
  • 5
  • 30
  • 71
0

Check out ?strptime for details on how to format dates.

strftime(strptime(date, "%m.%d"), "%b %d")
# [1] "Nov 17" "Dec 17" "Jan 18"
nograpes
  • 18,320
  • 1
  • 42
  • 64
0

Using data.table tstrsplit():

date_spl <- data.table::tstrsplit(date, "\\.")
paste0(month.abb[as.integer(date[[1]])], " 20", date[[2]])

# "Nov 2017" "Dec 2017" "Jan 2018"
sindri_baldur
  • 25,109
  • 3
  • 30
  • 57