Reputation: 1
I need help in R program to change date format from "May 29, 2015" to "05,29,2015".I tried this "housing$SaleDate<- as.Date(housing$SaleDate,"%Y%M%D")" but did not work. Thanks
Upvotes: 0
Views: 62
Reputation: 886948
After converting to Date
class, we may need format i.e.
library(lubridate)
str1 <- "May 29, 2015"
format(mdy(str1), '%m,%d,%Y')
[1] "05,29,2015"
For the OP's as.Date
, it would be
housing$SaleDate <- format(as.Date(housing$SaleDate, "%b %d, %Y"), "%m,%d,%Y")
Upvotes: 2