Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

date objects in month day format

Tags:

datetime

r

I was wondering if there is a way for R to turn this format into any date object. The format is 'month [space] day'. For example: Jan 1 or Jul 29 or Jul 30. I just want those examples to be read as a date object so I can manipulate them.

like image 796
Paolo Avatar asked Apr 06 '26 16:04

Paolo


1 Answers

Yes, use as.Date, but you also have to specify a year:

x <- c("Jan 1", "Jul 29", "Jul 30")

as.Date(paste("2012", x), format="%Y %b %d")
[1] "2012-01-01" "2012-07-29" "2012-07-30"

See ?as.Date for more help on Date objects, and ?strptime for help on the formatting codes.

like image 88
Andrie Avatar answered Apr 09 '26 07:04

Andrie



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!