[R] Error in length of vector ?

Petr Pikal petr.pikal at precheza.cz
Fri Mar 2 14:08:56 CET 2007


Hi

you stepped on a difference between POSIXct and POSIXlt

Details
There are two basic classes of date/times. Class "POSIXct" represents 
the (signed) number of seconds since the beginning of 1970 as a 
***numeric vector***. Class "POSIXlt" is a ***named list*** of 
vectors representing 

so you need to change your POSIXlt - named list to POSIXct by

as.POSIXct(your vector)

HTH
Petr

Maybe it could be useful to give some kind of warning into the help 
page of strptime e.g.

Be aware of length of an objects created by strptime as POSIXlt 
class.  It is always 9. See Details section of  DateTimeClasses.

 
On 2 Mar 2007 at 12:33, Sérgio Nunes wrote:

Date sent:      	Fri, 2 Mar 2007 12:33:46 +0000
From:           	"Sérgio Nunes" <snunes at gmail.com>
To:             	r-help at stat.math.ethz.ch
Subject:        	[R] Error in length of vector ?

> Hi,
> 
> I'm having a weird result with the length() function:
> 
> >a
> [... omited ...]
> [9994] NA                    "2003-12-03 16:37:00" "2002-06-26
> 18:43:00" [9997] "2005-07-04 04:00:00" "2007-02-16 22:09:00"
> "2007-02-24 15:49:00" [10000] NA
> 
> > length(LastModified)
> [1] 9
> 
> > length(c(LastModified))
> [1] 9
> 
> I was expecting to get "10000" as an answer.
> I'm trying to bind two vector, and I keep getting the error - "number
> of rows of result is not a multiple of vector length". Thus I tested
> length and got this value.
> 
> Any hint?
> 
> Thanks in advance,
> Sérgio Nunes
> 
> ______________________________________________
> 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.

Petr Pikal
petr.pikal at precheza.cz



More information about the R-help mailing list