Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I print a dataframe in R will all decimal values

Tags:

I have a dataframe whose values I want to inspect, but when I print the dataframe, only 2 or 3 decimals are printed. I inspected the dataframe directly and confirmed that there are more decimal places than what is being printed.

So far I have tried print(df, digits=10) and options(digits=10) but these don't seem to be changing the print output.

Some screenshots:

Printed output with too few decimals

Printed output with too few decimals.

Actual data with all decimal values

Actual data with all decimal values.

like image 447
rcodingguy Avatar asked Oct 13 '18 14:10

rcodingguy


People also ask

How do I fix decimal places in R?

To format all decimal places in an R vector and data frame, we can use formattable function of formattable package where we can specify the number of digits after decimal places.

How do I convert a whole data frame to numeric in R?

To convert columns of an R data frame from integer to numeric we can use lapply function. For example, if we have a data frame df that contains all integer columns then we can use the code lapply(df,as. numeric) to convert all of the columns data type into numeric data type.


1 Answers

I do not exactly know how you load your data. However, your screenshot looks like you are

looking at data in a tibble format.

x=1.1111
tibble(x) -> x
print(x)
A tibble: 1 x 1
      x
  <dbl>
1  1.11

if you convert it to a data.frame, you can print easily all digits:

as.data.frame(x) -> x
print(x)
       x
1 1.1111

Update: you can easily print a tibble in the format you are looking for using print.data.frame()

x = 1.234567890123456
tibble(x) -> x
print.data.frame(x, digits = 10)
#           x
#1 1.23456789

print.data.frame(x, digits = 11)
#             x
#1 1.2345678901
like image 94
captcoma Avatar answered Nov 15 '22 04:11

captcoma