[R] table and unique seems to behave differently
jdnewm|| @end|ng |rom dcn@d@v|@@c@@u@
Tue Dec 10 16:31:05 CET 2019
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:
>> 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
>> 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)
>#>  3.4 3.4
>#> c(3.4, 3.4)
>identical(x, c(3.4, 3.4))
>#>  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))
>#>  TRUE
>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.
More information about the R-help