Why does as_tibble() round floats to the nearest integer?

前端 未结 1 456
旧巷少年郎
旧巷少年郎 2020-12-11 03:59

When using as_tibble in dplyr 0.7.4 and R 3.4.1 I get the following outputs

mtcars %>% aggregate(disp ~ cyl, data=., mean) %>% as_tibble()
相关标签:
1条回答
  • 2020-12-11 04:29

    This is not a rounding, it's only a way for {tibble} to display data in a pretty way:

    > mtcars %>% 
    +   aggregate(disp ~ cyl, data=., mean) %>% 
    +   as_tibble() %>% 
    +   pull(disp)
    [1] 105.1364 183.3143 353.1000
    

    If you want to see more digits, you have to print a data.frame:

    > mtcars %>% 
    +   aggregate(disp ~ cyl, data=., mean) %>% 
    +   as_tibble() %>% 
    +   as.data.frame()
      cyl     disp
    1   4 105.1364
    2   6 183.3143
    3   8 353.1000
    

    (and yes, the two last lines are useless)

    0 讨论(0)
提交回复
热议问题