I would like to limit the number of decimals when a data frame is imported. My .txt input have 16 decimals to each row in collumn \"Value\". My dataframe look like that:
Here is.num
is TRUE
for numeric columns and FALSE
otherwise. We then apply round
to the numeric columns:
is.num <- sapply(DF, is.numeric)
DF[is.num] <- lapply(DF[is.num], round, 8)
If what you meant was not that you need to change the data frame but just that you want to display the data frame to 8 digits then it's just:
print(DF, digits = 8)
In dplyr 1.0.0 and later one can use across
within mutate
like this:
library(dplyr)
DF %>% mutate(across(is.numeric, ~ round(., 8)))