Rounding values in a dataframe in R -
this question has answer here:
i have dataframe values
shown below
january february march 0.02345 0.03456 0.04567 0.05432 0.06543 0.07654
i need command round each of these values 3 decimal points. output should shown below
january february march 0.023 0.035 0.046 0.054 0.065 0.077
in case data frame contains non-numeric characters may willing make use of function jeromy anglim:
round_df <- function(x, digits) { # round numeric variables # x: data frame # digits: number of digits round numeric_columns <- sapply(x, mode) == 'numeric' x[numeric_columns] <- round(x[numeric_columns], digits) x } round_df(data, 3)
i think it's neat , quick approach handle rounding problem across heterogeneous data frames.
Comments
Post a Comment