R: How to convert date from% b for different languages
I'm new to R and I'm having a hard time converting a date. Consider the following:
> 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
When i use
tz = ''
It uses my timezone which:
> Sys.timezone()
[1] "America/Sao_Paulo"
I've tried something like:
as.POSIXct(B, '%d-%b-%y', tz = 'America/New_York')
[1] NA
But it still didn't work. Any ideas?
Thank.
+3
Everton Reis
source
to share
1 answer
?as.POSIXct
gives:
If a format is given, remember that some of the BOM format is locale dependent and you may need to set LC_TIME accordingly via Sys.setlocale. This most often affects the use of% b,% B (monthly names) and% p (AM / PM).
Try calling Sys.setlocale()
before use %b
.
+5
Miroslav RadojeviΔ
source
to share