Why do tibbles and data.frames display decimal places a bit differently?

You are seeing the way the generic print function prints tribbles. If you want a tibble printed the same way as a data.frame use the print.data.frame() function instead of print(). Here is an example that shows some of the differences.

suppressPackageStartupMessages(library(tidyverse))
test_tbl <- tibble(
    aa = c(5.555555555551, 0.13333, 100.3),
    bb = c(3.3344444, 554444.123, 1123.556)
)

test_df <- data.frame(
    aa = c(5.555555555551, 0.13333, 100.3),
    bb = c(3.3344444, 554444.123, 1123.556)
)

# by default the generic print function only
# prints out the highest 3 digits dark and the 
# rest grayed out (but a reprex won't show 
# that). It only prints 2 digits
# after the decimal point
print(test_tbl)
#> # A tibble: 3 x 2
#>        aa        bb
#>     <dbl>     <dbl>
#> 1   5.56       3.33
#> 2   0.133 554444   
#> 3 100       1124
# if you want to print out a tibble in the
# same way a data.frame is use print.data.frame
# instead of
print(test_df)
#>           aa           bb
#> 1   5.555556 3.334444e+00
#> 2   0.133330 5.544441e+05
#> 3 100.300000 1.123556e+03
print.data.frame(test_tbl)
#>           aa           bb
#> 1   5.555556 3.334444e+00
#> 2   0.133330 5.544441e+05
#> 3 100.300000 1.123556e+03

Created on 2018-03-01 by the reprex package (v0.2.0).

2 Likes