[R] length() of vector after using strptime()

Prof Brian Ripley ripley at stats.ox.ac.uk
Fri Oct 10 16:37:26 CEST 2003


You have a POSIXlt object, a list of length 9.

Try ?as.POSIXct.

On 10 Oct 2003, David Whiting wrote:

> 
> Hi,
> 
> I am trying to parse a date (that is read in as a factor) and add it
> to a dataframe.  The length of the parsed date is shorter than the
> length of unparsed date and I therefore cannot add it to the dataframe:
> 
> > x
>   [1] 20030807 20030807 20030807 20030808 20030809 20030809 20030809 20030809
>   [9] 20030808 20030808 20030809 20030808 20030808 20030819 20030819 20030821
>         .
>         .
>         .
> [129] 20030808 20030805 20030726 20030810 20030805 20030811 20030816 20030818
> [137] 20030811
> 
> > length(x)
> [1] 137
> > xParsed <- strptime(as.character(x), "%Y%m%d")
> > 
> > xParsed
>   [1] "2003-08-07" "2003-08-07" "2003-08-07" "2003-08-08" "2003-08-09"
>   [6] "2003-08-09" "2003-08-09" "2003-08-09" "2003-08-08" "2003-08-08"
>         .
>         .
>         .
> [131] "2003-07-26" "2003-08-10" "2003-08-05" "2003-08-11" "2003-08-16"
> [136] "2003-08-18" "2003-08-11"
> > length(xParsed)
> [1] 9
> > 
> > dta$dateint <- xParsed
> Error in "$<-.data.frame"(`*tmp*`, "dateint", value = xParsed) : 
> 	replacement has 9 rows, data has 137
> 
> 
> 
> platform i686-pc-linux-gnu
> arch     i686             
> os       linux-gnu        
> system   i686, linux-gnu  
> status                    
> major    1                
> minor    8.0              
> year     2003             
> month    10               
> day      08               
> language R                
> 
> 
> Can someone tell me what I'm doing wrong?
> 
> Thanks.
> 
> 
> 
> 

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




More information about the R-help mailing list