3
Why do I get NA when I do this conversion from Character to Posixlt?
library(bReeze)
data(winddata)
tempo <- winddata[,1]
tempo[1:6] # Preview
# [1] "06.05.2009 11:20" "06.05.2009 11:30" "06.05.2009 11:40"
tempo_POSIX <- strptime(tempo, format = "%d.%m.%Y %H:%M")
sum(is.na(tempo_POSIX))
# [1] 6
valores_NA <- which(is.na(tempo_POSIX))
tempo[valores_NA]
# [1] "18.10.2009 00:00" "18.10.2009 00:10" "18.10.2009 00:20"
# [3] "18.10.2009 00:30" "18.10.2009 00:40" "18.10.2009 00:50"
As you can see, the values that have been converted to NA behave normally... they follow the same format as the others.
Interestingly, the error DOES NOT occur if I pass a value to the argument tz
tempo_POSIX <- strptime(tempo, format = "%d.%m.%Y %H:%M", tz = "GMT")
sum(is.na(tempo_POSIX))
# [1] 0
My system information is:
> sessionInfo()
R version 3.0.2 (2013-09-25)
Platform: x86_64-w64-mingw32/x64 (64-bit)
locale:
[1] LC_COLLATE=Portuguese_Brazil.1252 LC_CTYPE=Portuguese_Brazil.1252
[3] LC_MONETARY=Portuguese_Brazil.1252 LC_NUMERIC=C
[5] LC_TIME=Portuguese_Brazil.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] bReeze_0.4-0
loaded via a namespace (and not attached):
[1] tools_3.0.2
Here it works smoothly.
tempo_POSIX <- strptime(tempo, format = "%d.%m.%Y %H:%M")
sum(is.na(tempo_POSIX))
[1] 0
# [1] 6
– Evandro Dalbem
@Djongs, I don’t understand your output... After all, the number of missings you get is
0
or6
? And the error keeps happening to me... So I edited the question and put my system information there.– RogerioJB
Rogério, this result varies according to the locale, because of daylight saving time. Djongs system must be with another locale. @Djongs to play the example, run
Sys.setenv(TZ='America/Sao_Paulo')
before.– Carlos Cinelli