【问题标题】:Getting 1 decimal place from summarise when option "digits" is set to 7Getting 1 decimal place from summarise when option "digits" is set to 7
【发布时间】:2018-07-25 11:06:21
【问题描述】:

当我将68/70 相除,然后在命令行中取* 100 时,我得到97.14286,但是当我在summarise(perc_survived = (survived/N)*100) 中包含该公式时,输出为97.1。为什么会这样?
我检查了getOption("digits") 并返回了7。输出列标记为double,那为什么要截断小数位呢?

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

【问题讨论】:

  • 如果您可以共享您的数据,那么人们会更容易帮助您
  • 这对我来说没问题,data.frame(survived = 68, N = 70)%>% summarise(new = (survived/N)*100) - 97.14286
  • 啊哈...但这让我很兴奋97.1...tibble(survived = 68, N = 70)%>% summarise(new = (survived/N)*100)

标签: r dplyr rstudio


【解决方案1】:

只是tibble打印格式,见下图:

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

【讨论】:

  • 或者...%>% pull(new) :)
猜你喜欢
  • 2023-02-14
  • 2022-06-03
  • 1970-01-01
  • 2022-12-02
  • 1970-01-01
  • 2017-03-22
  • 1970-01-01
  • 2022-12-01
  • 1970-01-01
相关资源
最近更新 更多