Answers for "rounding all decimals with 5 places dataframe"

C++
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

Code answers related to "rounding all decimals with 5 places dataframe"

Browse Popular Code Answers by Language