[R] problem with length()

Jacob Etches jacob.etches at utoronto.ca
Tue Jul 17 03:34:15 CEST 2007


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}}



More information about the R-help mailing list