John Finley
John Finley

Reputation: 11

Getting 1 decimal place from summarise when option "digits" is set to 7

When I divide 68/70 then take * 100 at the command line I get 97.14286 but when I include that formula in summarise(perc_survived = (survived/N)*100) the output is 97.1. Why is that so?
I checked getOption("digits") and got back 7. The output column is labeled as double, so why the truncated decimal place?

summarise(N = n(), survived = sum(Survived), perc_survived = (survived/N)*100)

Upvotes: 1

Views: 562

Answers (1)

zx8754
zx8754

Reputation: 56149

It is just tibble print formatting, see below:

identical(
  tibble(survived = 68, N = 70) %>% summarise(new = (survived/N)*100) %>% .$new,
  68/70 * 100
  )
# [1] TRUE

Upvotes: 2

Related Questions