[R] identical()
Gabor Grothendieck
ggrothendieck at gmail.com
Mon Aug 16 23:54:28 CEST 2010
On Mon, Aug 16, 2010 at 5:47 PM, array chip <arrayprofile at yahoo.com> wrote:
> Hi, I am really puzzled by this. hope someone can help me
>
> I have a 2 small data frames "a" and "b" derived from a larger data frames. They
> look exactly the same to me, but identical() always returns FALSE.
>
>> a
> a b
> 2 10011048 L
> 4 10011048 R
> 6 10011049 L
> 8 10011049 R
>> b
> a b
> 1 10011048 L
> 3 10011048 R
> 5 10011049 L
> 7 10011049 R
>
>> identical(a,b)
> [1] FALSE
>
> some information about the attributes of the 2 data frames:
>
>> class(a)
> [1] "data.frame"
>> class(b)
> [1] "data.frame"
>> class(a$a)
> [1] "integer"
>> class(a$b)
> [1] "character"
>> class(b$a)
> [1] "integer"
>> class(b$b)
> [1] "character"
>
>
> However, if I generate these 2 data frame from scratches, identical() would
> returns TRUE
>
>>x<-as.data.frame(cbind(a=c(10011048,10011048,10011049,10011049),b=c('L','R','L','R')))
>>)
>>y<-as.data.frame(cbind(a=c(10011048,10011048,10011049,10011049),b=c('L','R','L','R')))
>>)
>
>> identical(x,y)
> [1] TRUE
>
> Looks like a & b objects takes some invisible residual information from the
> larger data frame where they were derived, which is not the same between them.
> But what is it?
>
Try dput(a) and dput(b) and carefully compare the two outputs.
More information about the R-help
mailing list