我是 R 新手,在转换日期时遇到了麻烦。考虑以下:
> A <- '30-Abr-17' #Portuguese
> B <- '30-Apr-17' #English
> as.POSIXct(A, '%d-%b-%y', tz = '')
[1] "2017-04-30 -03"
> as.POSIXct(B, '%d-%b-%y', tz = '')
[1] NA
当我使用
tz = ''
它使用我的时区,即:
> Sys.timezone()
[1] "America/Sao_Paulo"
我试过类似的东西:
as.POSIXct(B, '%d-%b-%y', tz = 'America/New_York')
[1] NA
但它仍然没有工作。有什么见解吗?
谢谢。
请您参考如下方法:
?as.POSIXct
给出:
If format is specified, remember that some of the format specifications are locale-specific, and you may need to set the LC_TIME category appropriately via Sys.setlocale. This most often affects the use of %b, %B (month names) and %p (AM/PM).
尝试调用
Sys.setlocale()
使用前
%b
.