Bigchao
Bigchao

Reputation: 1756

Convert string into Date value in R

I have a array containing date values in a unusual way.

datevalue <- c("6m6d", "6m10d","12m31d")

"m" stands for: month, "d" stands for: day I want to convert it into 4 digits date value for further calculation.

6m6d : 0606

6m10d : 0610

12m31d : 1231

Any suggestions are welcome, thanks a lot!

Upvotes: 1

Views: 206

Answers (1)

Julien Navarre
Julien Navarre

Reputation: 7830

Hi I think you can achieve that with : format(as.Date(datevalue, format = "%mm%dd"), "%m%d") (Note that as.Date(datevalue, format = "%mm%dd") returns the date for the current year)

Upvotes: 1

Related Questions