[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.
Alain
________________________________
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)
>unique(x)
>#> [1] 3.4 3.4
>dput(x)
>#> 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
>https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-help&data=02%7C01%7C%7C74bb1eeaeb444a6499e508d77d85fba3%7C7ab090d4fa2e4ecfbc7c4127b4d582ec%7C0%7C0%7C637115886725989409&sdata=mU3K2kH%2FAwxdEQ%2BOWVYBhqNLbWGkWzmtfgx92D1DNF8%3D&reserved=0
>PLEASE do read the posting guide
>https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.R-project.org%2Fposting-guide.html&data=02%7C01%7C%7C74bb1eeaeb444a6499e508d77d85fba3%7C7ab090d4fa2e4ecfbc7c4127b4d582ec%7C0%7C0%7C637115886725989409&sdata=hTxOssdYb%2FcvvSFQyQZ5GBWkpHzsIrbtqJbgCgW2LPw%3D&reserved=0
>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