无法在R语言中转换日期格式

0 r date na

我试图在R语言中转换为日期,然后我得到了NA.尝试设置LOCALE但仍然发行.请指教.这是我想要做的快照:

## 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"
Run Code Online (Sandbox Code Playgroud)

小智 6

这应该工作:

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"
Run Code Online (Sandbox Code Playgroud)