[R] table and unique seems to behave differently

Alain Guillet @|@|n@gu|||et @end|ng |rom uc|ouv@|n@be
Tue Dec 10 17:52:49 CET 2019

Thanks a lot, it answers my question.

De : Jeff Newmiller <jdnewmil using dcn.davis.ca.us>
Envoy� : mardi 10 d�cembre 2019 16:31
� : r-help using r-project.org <r-help using r-project.org>; Duncan Murdoch <murdoch.duncan using gmail.com>; Alain Guillet <alain.guillet using uclouvain.be>; r-help using r-project.org <r-help using r-project.org>
Objet : Re: [R] table and unique seems to behave differently

I think the question was about table vs unique. Table groups by character representation, unique groups by the underlying representation.

On December 10, 2019 7:03:34 AM PST, Duncan Murdoch <murdoch.duncan using gmail.com> wrote:
>On 10/12/2019 3:53 a.m., Alain Guillet wrote:
>> Hi,
>> I have a vector (see below the dput) and I use unique on it to get
>unique values. If I then sort the result of the vector obtained by
>unique, I see some elements that look like identical. I suspect it
>could be a matter of rounded values but table gives a different result:
>unlike unique output which contains "3.4  3.4", table has only one cell
>for 3.4.
>> Can anybody know why I get results that look like incoherent between
>the two functions?
>dput() does some rounding, so it doesn't necessarily reproduce values
>exactly.  For example,
>x <- c(3.4, 3.4 + 1e-15)
>#> [1] 3.4 3.4
>#> c(3.4, 3.4)
>identical(x, c(3.4, 3.4))
>#> [1] FALSE
>If you really want to see exact values, you can use the "hexNumeric"
>option to dput():
>dput(x, control = "hexNumeric")
>#> c(0x1.b333333333333p+1, 0x1.b333333333335p+1)
>identical(x, c(0x1.b333333333333p+1, 0x1.b333333333335p+1))
>#> [1] TRUE
>Duncan Murdoch
>R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
>PLEASE do read the posting guide
>and provide commented, minimal, self-contained, reproducible code.

Sent from my phone. Please excuse my brevity.

	[[alternative HTML version deleted]]

More information about the R-help mailing list