Controlling decimal places displayed in a tibble. Understanding what pillar.sigfig does

与世无争的帅哥 提交于 2021-02-07 13:36:53

问题


I have a csv file weight.csv with the following contents.

weight,weight_selfreport
81.5,81.66969147005445
72.6,72.59528130671505
92.9,93.01270417422867
79.4,79.4010889292196
94.6,96.64246823956442
80.2,79.4010889292196
116.2,113.43012704174228
95.4,95.73502722323049
99.5,99.8185117967332

If I do

library(readr)
Df <- read_csv('weight.csv')
Df

I get

# A tibble: 9 x 2
  weight weight_selfreport
   <dbl>             <dbl>
1   81.5              81.7
2   72.6              72.6
3   92.9              93.0
4   79.4              79.4
5   94.6              96.6
6   80.2              79.4
7  116.              113. 
8   95.4              95.7
9   99.5              99.8

If I convert that tibble to a normal data frame, I'll see more digits.

as.data.frame(Df)
  weight weight_selfreport
1   81.5          81.66969
2   72.6          72.59528
3   92.9          93.01270
4   79.4          79.40109
5   94.6          96.64247
6   80.2          79.40109
7  116.2         113.43013
8   95.4          95.73503
9   99.5          99.81851

Initially I thought that if I wanted to get this type of display for the tibble, I thought I would do options(pillar.sigfig = 5).

However, that's not what it does.

options(pillar.sigfig = 5)
Df
# A tibble: 9 x 2
   weight weight_selfreport
    <dbl>             <dbl>
1  81.5              81.670
2  72.600            72.595
3  92.9              93.013
4  79.4              79.401
5  94.6              96.642
6  80.2              79.401
7 116.2             113.43 
8  95.4              95.735
9  99.5              99.819

And so I see that pillar.sigfig is about controlling significant digits not decimals places.

Fine but

  • Why is (row 2, col 1) 72.6 being displayed as 72.600?
  • What can I do, or can I do anything, to get five decimals places?

来源:https://stackoverflow.com/questions/55018308/controlling-decimal-places-displayed-in-a-tibble-understanding-what-pillar-sigf

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!