Delving into the murky world of dates and times I found this: dates <- c("02/27/92", "02/27/92", "01/14/92", "02/28/92", "02/01/92")> times <- c("23:03:20", "22:29:56", "01:03:30", "18:21:03", "16:56:26") > x <- paste(dates, times) > z <- strptime(x, "%m/%d/%y %H:%M:%S") > z[1] "1992-02-27 23:03:20" "1992-02-27 22:29:56" "1992-01-14 01:03:30" [4] "1992-02-28 18:21:03" "1992-02-01 16:56:26" which I understand. But then> length(dates)[1] 5> length(times)[1] 5> length(z)[1] 9>which I don't. It seems that length of a POSIXlt vector (which z is), always returns 9. David Scott PS: Using 1.9.0 on linux _________________________________________________________________ David Scott Department of Statistics, Tamaki Campus The University of Auckland, PB 92019 Auckland NEW ZEALAND Phone: +64 9 373 7599 ext 86830 Fax: +64 9 373 7000 Email: d.scott at auckland.ac.nz Graduate Officer, Department of Statistics
Here's a hint:> str(unclass(z))List of 9 $ sec : int [1:5] 20 56 30 3 26 $ min : int [1:5] 3 29 3 21 56 $ hour : int [1:5] 23 22 1 18 16 $ mday : int [1:5] 27 27 14 28 1 $ mon : int [1:5] 1 1 0 1 1 $ year : int [1:5] 92 92 92 92 92 $ wday : int [1:5] 4 4 2 5 6 $ yday : int [1:5] 57 57 13 58 31 $ isdst: int [1:5] 0 0 0 0 0 Andy> From: David Scott > > Delving into the murky world of dates and times I found this: > > dates <- c("02/27/92", "02/27/92", "01/14/92", "02/28/92", "02/01/92") > > times <- c("23:03:20", "22:29:56", "01:03:30", "18:21:03", > "16:56:26") > > x <- paste(dates, times) > > z <- strptime(x, "%m/%d/%y %H:%M:%S") > > z > [1] "1992-02-27 23:03:20" "1992-02-27 22:29:56" "1992-01-14 01:03:30" > [4] "1992-02-28 18:21:03" "1992-02-01 16:56:26" > > which I understand. But then > > > length(dates) > [1] 5 > > length(times) > [1] 5 > > length(z) > [1] 9 > > > > which I don't. > > It seems that length of a POSIXlt vector (which z is), always > returns 9. > > David Scott > > PS: Using 1.9.0 on linux > > > > > > _________________________________________________________________ > David Scott Department of Statistics, Tamaki Campus > The University of Auckland, PB 92019 > Auckland NEW ZEALAND > Phone: +64 9 373 7599 ext 86830 Fax: +64 9 373 7000 > Email: d.scott at auckland.ac.nz > > > Graduate Officer, Department of Statistics > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > >
On Thu, May 06, 2004 at 02:00:25PM +1200, David Scott wrote:> > Delving into the murky world of dates and times I found this: > > dates <- c("02/27/92", "02/27/92", "01/14/92", "02/28/92", "02/01/92") > > times <- c("23:03:20", "22:29:56", "01:03:30", "18:21:03", "16:56:26") > > x <- paste(dates, times) > > z <- strptime(x, "%m/%d/%y %H:%M:%S") > > z > [1] "1992-02-27 23:03:20" "1992-02-27 22:29:56" "1992-01-14 01:03:30" > [4] "1992-02-28 18:21:03" "1992-02-01 16:56:26" > > which I understand. But then > > > length(dates) > [1] 5 > > length(times) > [1] 5 > > length(z) > [1] 9 > > > > which I don't. > > It seems that length of a POSIXlt vector (which z is), always returns 9.Yup, as documented. It takes a little getting used to, but if you read help(DateTimeClasses), preferably a few times and with coffee or tea at your side, it all becomes clear. What you wanted was possibly a cast to POSIXct:> length(z)[1] 9> length(as.POSIXct(z))[1] 5 Hth, Dirk -- The relationship between the computed price and reality is as yet unknown. -- From the pac(8) manual page
Issuing the command: unclass(z) will show what is going on here. David Scott <d.scott <at> auckland.ac.nz> writes: : : Delving into the murky world of dates and times I found this: : : dates <- c("02/27/92", "02/27/92", "01/14/92", "02/28/92", "02/01/92") : > times <- c("23:03:20", "22:29:56", "01:03:30", "18:21:03", "16:56:26") : > x <- paste(dates, times) : > z <- strptime(x, "%m/%d/%y %H:%M:%S") : > z : [1] "1992-02-27 23:03:20" "1992-02-27 22:29:56" "1992-01-14 01:03:30" : [4] "1992-02-28 18:21:03" "1992-02-01 16:56:26" : : which I understand. But then : : > length(dates) : [1] 5 : > length(times) : [1] 5 : > length(z) : [1] 9 : > : : which I don't. : : It seems that length of a POSIXlt vector (which z is), always returns 9. : : David Scott : : PS: Using 1.9.0 on linux : : : _________________________________________________________________ : David Scott Department of Statistics, Tamaki Campus : The University of Auckland, PB 92019 : Auckland NEW ZEALAND : Phone: +64 9 373 7599 ext 86830 Fax: +64 9 373 7000 : Email: d.scott <at> auckland.ac.nz : : Graduate Officer, Department of Statistics : : ______________________________________________ : R-help <at> stat.math.ethz.ch mailing list : https://www.stat.math.ethz.ch/mailman/listinfo/r-help : PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html : :