POSIXlt is a list structure of 9 elements (see ?POSIXlt). You can see
that in the data below:
> x <-
as.POSIXlt(c('2007-01-01','2007-02-01','2007-03-31'))
> length(x)
[1] 9> unclass(x)
$sec
[1] 0 0 0
$min
[1] 0 0 0
$hour
[1] 0 0 0
$mday
[1] 1 1 31
$mon
[1] 0 1 2
$year
[1] 107 107 107
$wday
[1] 1 4 6
$yday
[1] 0 31 89
$isdst
[1] 0 0 0
attr(,"tzone")
[1] "GMT"> length(as.POSIXct(x))
[1] 3
What you probably want to do is to use the POSIXct class.
On 7/16/07, Jacob Etches <jacob.etches at utoronto.ca>
wrote:> In the following, can anyone tell me why length(eee) returns 9? I
> was expecting 15398, and when I try to add this vector to a data
> frame with that many rows, it fails complaining that the vector is of
> length 9. In what I thought was an identical situation with a
> related dataset, the same code worked as expected.
>
> > length(fff)
> [1] 15398
> > str(fff)
> int [1:15398] 20010102 20010102 20010102 20010103 20010103 20010102
> 20010102 20010104 20010103 20010102 ...
> > fff[1:12]
> [1] 20010102 20010102 20010102 20010103 20010103 20010102 20010102
> 20010104 20010103 20010102 20010105 20010103
> > eee <- as.POSIXlt(strptime(fff,"%Y%m%d"))
> > length(eee)
> [1] 9
> > eee[1:12]
> [1] "2001-01-02" "2001-01-02" "2001-01-02"
"2001-01-03" "2001-01-03"
> "2001-01-02" "2001-01-02" "2001-01-04"
"2001-01-03" "2001-01-02"
> "2001-01-05" "2001-01-03"
> > str(eee)
> 'POSIXlt', format: chr [1:15398] "2001-01-02"
"2001-01-02"
> "2001-01-02" "2001-01-03" "2001-01-03"
"2001-01-02" "2001-01-02"
> "2001-01-04" "2001-01-03" ...
>
>
>
> Many thanks in advance,
> Jacob Etches
>
>
> Doctoral candidate, Epidemiology Program
> Department of Public Health Sciences, University of Toronto Faculty
> of Medicine
>
> Research Associate
> Institute for Work & Health
> 800-481 University Avenue, Toronto, Ontario, Canada M5G 2E9
> T: 416.927.2027 ext. 2290
> F: 416.927.4167
> jetches at iwh.on.ca
> www.iwh.on.ca
>
>
>
>
>
> This e-mail may contain confidential information for the sol...{{dropped}}
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
--
Jim Holtman
Cincinnati, OH
+1 513 646 9390
What is the problem you are trying to solve?