Full_Name: Petr Simecek Version: 2.5.1, 2.6.1 OS: Windows XP Submission from: (NULL) (195.113.231.2) Several times I have experienced that a length of a POSIXt vector has not been computed right. Example: tv<-structure(list(sec = c(50, 0, 55, 12, 2, 0, 37, NA, 17, 3, 31 ), min = c(1L, 10L, 11L, 15L, 16L, 18L, 18L, NA, 20L, 22L, 22L ), hour = c(12L, 12L, 12L, 12L, 12L, 12L, 12L, NA, 12L, 12L, 12L), mday = c(13L, 13L, 13L, 13L, 13L, 13L, 13L, NA, 13L, 13L, 13L), mon = c(5L, 5L, 5L, 5L, 5L, 5L, 5L, NA, 5L, 5L, 5L), year = c(105L, 105L, 105L, 105L, 105L, 105L, 105L, NA, 105L, 105L, 105L), wday = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, NA, 1L, 1L, 1L), yday = c(163L, 163L, 163L, 163L, 163L, 163L, 163L, NA, 163L, 163L, 163L), isdst = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, -1L, 1L, 1L, 1L)), .Names = c("sec", "min", "hour", "mday", "mon", "year", "wday", "yday", "isdst" ), class = c("POSIXt", "POSIXlt")) print(tv) # print 11 time points (right) length(tv) # returns 9 (wrong) I have tried that on several computers with/without switching to English locales, i.e. Sys.setlocale("LC_TIME", "en"). I have searched a help pages but I cannot imagine how that could be OK.
simecek at gmail.com wrote:> Full_Name: Petr Simecek > Version: 2.5.1, 2.6.1 > OS: Windows XP > Submission from: (NULL) (195.113.231.2) > > > Several times I have experienced that a length of a POSIXt vector has not been > computed right. > > Example: > > tv<-structure(list(sec = c(50, 0, 55, 12, 2, 0, 37, NA, 17, 3, 31 > ), min = c(1L, 10L, 11L, 15L, 16L, 18L, 18L, NA, 20L, 22L, 22L > ), hour = c(12L, 12L, 12L, 12L, 12L, 12L, 12L, NA, 12L, 12L, > 12L), mday = c(13L, 13L, 13L, 13L, 13L, 13L, 13L, NA, 13L, 13L, > 13L), mon = c(5L, 5L, 5L, 5L, 5L, 5L, 5L, NA, 5L, 5L, 5L), year = c(105L, > 105L, 105L, 105L, 105L, 105L, 105L, NA, 105L, 105L, 105L), wday = c(1L, > 1L, 1L, 1L, 1L, 1L, 1L, NA, 1L, 1L, 1L), yday = c(163L, 163L, > 163L, 163L, 163L, 163L, 163L, NA, 163L, 163L, 163L), isdst = c(1L, > 1L, 1L, 1L, 1L, 1L, 1L, -1L, 1L, 1L, 1L)), .Names = c("sec", > "min", "hour", "mday", "mon", "year", "wday", "yday", "isdst" > ), class = c("POSIXt", "POSIXlt")) > > print(tv) > # print 11 time points (right) > > length(tv) > # returns 9 (wrong) > > I have tried that on several computers with/without switching to English > locales, i.e. Sys.setlocale("LC_TIME", "en"). I have searched a help pages but I > cannot imagine how that could be OK. > >Given the way you define it, you should be able to imagine it! It's a list of length 9: sec, min, hour,..., isdst. -- O__ ---- Peter Dalgaard ?ster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
On 12/11/2007 6:20 AM, simecek at gmail.com wrote:> Full_Name: Petr Simecek > Version: 2.5.1, 2.6.1 > OS: Windows XP > Submission from: (NULL) (195.113.231.2) > > > Several times I have experienced that a length of a POSIXt vector has not been > computed right. > > Example: > > tv<-structure(list(sec = c(50, 0, 55, 12, 2, 0, 37, NA, 17, 3, 31 > ), min = c(1L, 10L, 11L, 15L, 16L, 18L, 18L, NA, 20L, 22L, 22L > ), hour = c(12L, 12L, 12L, 12L, 12L, 12L, 12L, NA, 12L, 12L, > 12L), mday = c(13L, 13L, 13L, 13L, 13L, 13L, 13L, NA, 13L, 13L, > 13L), mon = c(5L, 5L, 5L, 5L, 5L, 5L, 5L, NA, 5L, 5L, 5L), year = c(105L, > 105L, 105L, 105L, 105L, 105L, 105L, NA, 105L, 105L, 105L), wday = c(1L, > 1L, 1L, 1L, 1L, 1L, 1L, NA, 1L, 1L, 1L), yday = c(163L, 163L, > 163L, 163L, 163L, 163L, 163L, NA, 163L, 163L, 163L), isdst = c(1L, > 1L, 1L, 1L, 1L, 1L, 1L, -1L, 1L, 1L, 1L)), .Names = c("sec", > "min", "hour", "mday", "mon", "year", "wday", "yday", "isdst" > ), class = c("POSIXt", "POSIXlt")) > > print(tv) > # print 11 time points (right) > > length(tv) > # returns 9 (wrong)tv is a list of length 9. The answer is right, your expectation is wrong.> > I have tried that on several computers with/without switching to English > locales, i.e. Sys.setlocale("LC_TIME", "en"). I have searched a help pages but I > cannot imagine how that could be OK.See this in ?POSIXt: Class '"POSIXlt"' is a named list of vectors... You could define your own length measurement as length.POSIXlt <- function(x) length(x$sec) and you'll get the answer you expect, but be aware that length.XXX methods are quite rare, and you may surprise some of your users. Duncan Murdoch
ripley at stats.ox.ac.uk
2007-Dec-12 14:45 UTC
[Rd] Wrong length of POSIXt vectors (PR#10507)
It is right: it is a list of length 9. You even constructed it as such a list! On Tue, 11 Dec 2007, simecek at gmail.com wrote:> Full_Name: Petr Simecek > Version: 2.5.1, 2.6.1 > OS: Windows XP > Submission from: (NULL) (195.113.231.2) > > > Several times I have experienced that a length of a POSIXt vector has not been > computed right. > > Example: > > tv<-structure(list(sec = c(50, 0, 55, 12, 2, 0, 37, NA, 17, 3, 31 > ), min = c(1L, 10L, 11L, 15L, 16L, 18L, 18L, NA, 20L, 22L, 22L > ), hour = c(12L, 12L, 12L, 12L, 12L, 12L, 12L, NA, 12L, 12L, > 12L), mday = c(13L, 13L, 13L, 13L, 13L, 13L, 13L, NA, 13L, 13L, > 13L), mon = c(5L, 5L, 5L, 5L, 5L, 5L, 5L, NA, 5L, 5L, 5L), year = c(105L, > 105L, 105L, 105L, 105L, 105L, 105L, NA, 105L, 105L, 105L), wday = c(1L, > 1L, 1L, 1L, 1L, 1L, 1L, NA, 1L, 1L, 1L), yday = c(163L, 163L, > 163L, 163L, 163L, 163L, 163L, NA, 163L, 163L, 163L), isdst = c(1L, > 1L, 1L, 1L, 1L, 1L, 1L, -1L, 1L, 1L, 1L)), .Names = c("sec", > "min", "hour", "mday", "mon", "year", "wday", "yday", "isdst" > ), class = c("POSIXt", "POSIXlt")) > > print(tv) > # print 11 time points (right) > > length(tv) > # returns 9 (wrong) > > I have tried that on several computers with/without switching to English > locales, i.e. Sys.setlocale("LC_TIME", "en"). I have searched a help > pages but I cannot imagine how that could be OK. > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595