identical()

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

identical()

array chip
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?

Thanks

John

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: identical()

Erik Iverson-3

Hello,

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

Do these really look "exactly the same" to you?

The first column (the row.names) are clearly different, thus they are
not identical.

See ?row.names

>
> 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?
>
> Thanks
>
> John
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: identical()

Gabor Grothendieck
In reply to this post by array chip
On Mon, Aug 16, 2010 at 5:47 PM, array chip <[hidden email]> 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: identical()

array chip
In reply to this post by Erik Iverson-3
Oops, I overlooked the row names. Sorry for my carelessness.

Thanks



----- Original Message ----
From: Erik Iverson <[hidden email]>
To: array chip <[hidden email]>
Cc: [hidden email]
Sent: Mon, August 16, 2010 2:53:37 PM
Subject: Re: [R] identical()


Hello,

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

Do these really look "exactly the same" to you?

The first column (the row.names) are clearly different, thus they are
not identical.

See ?row.names

>
> 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?
>
> Thanks
>
> John
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: identical()

Wu Gong
In reply to this post by array chip
Hi John,

They are different as Erik said.

> identical(a,b)
[1] FALSE
> row.names(a)
[1] "2" "4" "6" "8"
> row.names(b)
[1] "1" "3" "5" "7"
> row.names(a) <- NULL
> row.names(b) <- NULL
> identical(a,b)
[1] TRUE


Regards,

Wu

array chip wrote
> 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
Reply | Threaded
Open this post in threaded view
|

Re: identical()

Jorge I Velez
In reply to this post by array chip
Hi,

Take a look at this:

> identical(a,b)
[1] FALSE
> all.equal(a,b)
[1] "Attributes: < Component 2: 4 string mismatches >"
> rownames(a) <- rownames(b) <- NULL
> identical(a,b)
[1] TRUE
> all.equal(a,b)
[1] TRUE

HTH,
Jorge


On Mon, Aug 16, 2010 at 5:47 PM, array chip <> 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?
>
> Thanks
>
> John
>
> ______________________________________________
> [hidden email] 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.
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.