user3759240
user3759240

Reputation: 5

Not able to convert date format in R Language

I am trying to convert into date in the R Language then i have getting NA. Tried setting up the LOCALE but still issue. Please advise. Here is the snapshot of what i am trying to do :

## Stored the date into X**
x <- c("2014-12-01", "2014-12-15", "2014-12-20", "2014-12-25")

## Tring to convert the date in the format dd-MMM-YYYY BUT GETTING error**
as.Date(x,"%d-%B-%y")
[1] NA NA NA NA

## Tried setting the LOCALE. See the current locale below**
Sys.getlocale("LC_TIME");
[1] "English_United States.1252"

Upvotes: 0

Views: 155

Answers (1)

user3710546
user3710546

Reputation:

This should work:

x <- c("2014-12-01", "2014-12-15", "2014-12-20", "2014-12-25")
format(as.Date(x), "%d-%b-%Y")
#[1] "01-Dec-2014" "15-Dec-2014" "20-Dec-2014" "25-Dec-2014"

Upvotes: 6

Related Questions