Answers for "convert all numeric columns to percentages R"

R
0

convert all numeric columns to percentages R

myfun <- function(x) {
  if(is.numeric(x)){ 
    ifelse(is.na(x), x, paste0(round(x*100L, 1), "%")) 
  } else x 
}

df1 %>% mutate_each(funs(myfun))
#   name somevariable othervariable
# 1   A1        13.4%         53.4%
# 2   A1        54.8%          <NA>
# 3   B1        36.9%         36.9%
# 4   B1         <NA>         33.3%
Posted by: Guest on November-18-2020

Code answers related to "convert all numeric columns to percentages R"

Browse Popular Code Answers by Language