[R] identical(length(x), 1) returns FALSE, but print(length(x)) is 1, length(x)==1 is TRUE, and is.integer(lenght(x)) is TRUE????

Thomas Lumley tlumley at u.washington.edu
Tue Sep 15 19:12:24 CEST 2009


On Tue, 15 Sep 2009, Corrado wrote:

> On Tuesday 15 September 2009 17:28:02 Gavin Simpson wrote:
>> [note you don't give us your x so I'm making this up - This is what
>> Duncan was going on about in an earlier thread, give us something we can
>> just paste into R and it works]
>
> Dear Gavin,
>
> I do not understand what more information! Take any vector of length 1, for
> example x<-1. Plus all the command that where in my previous email ....
>
> What is the logic behind
>
> identical(length(x),1)
>
> being false?
>

length(x) is an integer, and 1 is a floating point number. They aren't identical, just equal, so 
identical(length(x), 1) is FALSE and length(x)==1 is TRUE.

identical(length(x), 1L) should be TRUE, since 1L is the way to specify an integer value of 1.


        -thomas

Thomas Lumley			Assoc. Professor, Biostatistics
tlumley at u.washington.edu	University of Washington, Seattle




More information about the R-help mailing list