Search code examples
rsubstringnumericsubstr

Getting last two digits of Sequence Date in R


I have sequence date:

names<-format(seq.Date(as.Date("2012-11-01"),as.Date("2012-12-01"),
                by = 'months'),format = "%Y%m")

How can I get the last two digit, like the result for last two digits of names[1] is 11?


Solution

  • Using the stringr package you can just put

    stringr::str_sub(string = names, start = -2, end = -1)