Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGZILLA #16620] Display of summary of numeric vector containing Inf is incorrect #6007

Open
MichaelChirico opened this issue May 18, 2020 · 5 comments

Comments

@MichaelChirico
Copy link
Owner

The display of a summary of a numeric vector containing Inf does not round correctly.

options(digits=22)
summary(c(.1,.2,.3,.4,.5),digits=22)
                Min.                  1st Qu.                   Median                     Mean                  3rd Qu. 

0.1000000000000000055511 0.2000000000000000111022 0.2999999999999999888978 0.2999999999999999888978 0.4000000000000000222045
Max.
0.5000000000000000000000

summary(c(.1,.2,.3,.4,Inf),digits=22)

Min. 1st Qu. Median Mean 3rd Qu. Max.
0 0 0 Inf 0 Inf

Note that the error is in the display, and not the calculation

x = summary(c(.1,.2,.3,.4,Inf))
print(as.vector(x))

[1] 0.1000000000000000055511 0.2000000000000000111022 0.2999999999999999888978 Inf 0.4000000000000000222045
[6] Inf


METADATA

  • Bug author - 8666f00c
  • Creation time - 2015-12-02 14:58:20 UTC
  • Bugzilla link
  • Status - RESOLVED FIXED
  • Alias - None
  • Component - Analyses
  • Version - R 3.2.2
  • Hardware - x86_64/x64/amd64 (64-bit) Windows 64-bit
  • Importance - P5 normal
  • Assignee - R-core
  • URL -
  • Modification time - 2015-12-13 14:14 UTC
@MichaelChirico
Copy link
Owner Author

The reason this happens is that the print method calls zapsmall() on the entries. Compared to Inf, every finite number is small.

I agree the behaviour is ugly. Perhaps only the finite values should be zapped?

On the other hand, summary.default prints ugly results by design (e.g. summary(123456) rounding the entries), so I'm not sure everyone would agree on changing this.


METADATA

  • Comment author - Duncan Murdoch
  • Timestamp - 2015-12-02 17:44:55 UTC

@MichaelChirico
Copy link
Owner Author

Created attachment 1941 [details]
Excludes infinite values in maximum calculation


METADATA

  • Comment author - 8666f00c
  • Timestamp - 2015-12-03 00:34:44 UTC

INCLUDED PATCH

@MichaelChirico
Copy link
Owner Author

Thanks for the response, knowing about zapsmall() really helps me understand this. A few comments though

Another issue with what I'm bringing up here is that it's not simply a matter of everything being small compared to infinity -- it seems that it simply truncates decimals places but otherwise respects significant digits

summary(c(11.1,22.2,33.3,44.4,Inf),digits=1)

Min. 1st Qu. Median Mean 3rd Qu. Max.
10 20 30 Inf 40 Inf

summary(c(11.1,22.2,33.3,44.4,Inf),digits=22)

Min. 1st Qu. Median Mean 3rd Qu. Max.
11 22 33 Inf 44 Inf

As to your example about summary(123456), while we might be able to argue about the ideal behavior here, I would not have submitted it as a bug report because at least there is an option to get it to display correct results.

summary(123456)

Min. 1st Qu. Median Mean 3rd Qu. Max.
123500 123500 123500 123500 123500 123500

summary(123456,digits=6)

Min. 1st Qu. Median Mean 3rd Qu. Max.
123456 123456 123456 123456 123456 123456

As it stands, printing summary with an Inf will provide mostly useless results if run on numeric data with an absolute value less than 1 no matter what options you provide. This is made more confusing by the fact that you get expected results if run on numeric data without decimal places.

In an attempt to not be a total leech, I followed through on where you pointed me to and attached a modification to /src/library/base/R/zapsmall.R that would fix this behavior (only added 1 line and modified another). In case it's thought that modification of zapsmall would mess up something else, I'll also make a change to /src/library/base/R/summary.R that only affects this specific issue.


METADATA

  • Comment author - 8666f00c
  • Timestamp - 2015-12-03 00:36:42 UTC

@MichaelChirico
Copy link
Owner Author

I can't figure out if there is a way to edit my patch or change old comments, but I wanted to say that I'm having trouble testing/compiling R at the moment. I've done it plenty of times before, but having some trouble on the current machine. It seems like it should be good to me, but I'm too new to know better.

Sorry about that.


METADATA

  • Comment author - 8666f00c
  • Timestamp - 2015-12-03 01:05:30 UTC

@MichaelChirico
Copy link
Owner Author

I've made a less extreme patch than yours, only changing the summary print and format methods, not zapsmall itself. Will commit after testing.


METADATA

  • Comment author - Duncan Murdoch
  • Timestamp - 2015-12-13 14:14:46 UTC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant