Answers for "how to round all numeric column types in r"

R
0

round all columns in R dataframe to 3 digits

round_df <- function(x, digits) {
    # round all numeric variables
    # x: data frame 
    # digits: number of digits to round
    numeric_columns <- sapply(x, mode) == 'numeric'
    x[numeric_columns] <-  round(x[numeric_columns], digits)
    x
}

round_df(data, 3)
Posted by: Guest on November-18-2020
-1

how to round all numeric column types in r

library(dplyr)
df %>% 
 mutate_if(is.numeric, round)
Posted by: Guest on November-17-2020

Code answers related to "how to round all numeric column types in r"

Browse Popular Code Answers by Language