2

The year and month is represented as 201603 representing March,2016. How to convert this numerical value into date format like "March-2016" or "2016-03" in R?

Sanjeev
  • 221
  • 1
  • 4
  • 8

1 Answers1

18

A date should always have a given day, therefore consider to add the day at the end of YYYYMM (in the example below 01 the first day of the month). Convert the numeric value to character and the character to a Date:

as.Date(paste0(as.character(201603), '01'), format='%Y%m%d')

tic-toc-choc
  • 815
  • 11
  • 26