[Rd] Unexpected behabiour of min, tapply and POSIXct/POSIXlt classes?
Carlos J. Gil Bellosta
cgb at datanalytics.com
Thu Oct 28 19:11:32 CEST 2010
Hello,
I found rather surprising the behaviour of POSIXct and POSIXlt classes
when combined with min and tapply.
The details can be deduced from the script below:
############# Start of the script ####################
before <- Sys.time()
Sys.sleep( 1 )
now1 <- now2 <- Sys.time()
my.times <- c( before, now1, now2 )
class( my.times ) ## [1] "POSIXct" "POSIXt"
min( my.times ) ## [1] "2010-10-28 18:52:17 CEST"
### So far, so good... but:
my.period <- c( "a", "b", "b" )
tapply( my.times, my.period, min )
## a b
## 1288284737 1288284780
## Where did my POSIXct class go?
my.times.lt <- as.POSIXlt( my.times )
min( my.times.lt ) ## [1] "2010-10-28 18:52:17 CEST"; good!
tapply( my.times.lt, my.period, min )
# $a
# [1] 17.449
#
# $b
# [1] 52
#
# Mensajes de aviso perdidos
# In ansmat[index] <- ans :
# número de items para para sustituir no es un múltiplo de la
longitud del reemplazo
#
# ¿? :(
############# End of the script ####################
Here are the details of my session (as reported by sessionInfo):
R version 2.12.0 (2010-10-15)
Platform: i386-pc-mingw32/i386 (32-bit)
locale:
[1] LC_COLLATE=Spanish_Spain.1252 LC_CTYPE=Spanish_Spain.1252
LC_MONETARY=Spanish_Spain.1252 LC_NUMERIC=C
[5] LC_TIME=Spanish_Spain.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] RODBC_1.3-2 plotrix_3.0
loaded via a namespace (and not attached):
[1] tools_2.12.0
I am running R on a Windows XP Box.
Thank you very much,
Carlos J. Gil Bellosta
http://www.datanalytics.com
More information about the R-devel
mailing list