Search
 
SCRIPT & CODE EXAMPLE
 

R

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%
Comment

PREVIOUS NEXT
Code Example
R :: r extract top values from data frame 
R :: quartile in r 
R :: regression in r with many variables 
R :: moving average in r 
R :: reduce ggtitle size 
R :: make gif r 
R :: finding index of element in r 
R :: How to calculate standardized residuals in R 
R :: if a condition is true skip loop r 
R :: angular material number picker 
R :: how to load html file to r studio 
R :: ggplot2 reverse order of scale_brewer color 
R :: logistic distribution CDF in r 
R :: R construct a named list 
R :: remove a loaded library from workspace r 
R :: colorblind-friendly palette in r 
R :: "R" multi-line comment 
R :: save data frames in a loop r 
R :: how to pull all 500 stocks r 
Rust :: rust create folder 
Rust :: rust sleep 
Rust :: 2d vector rust 
Rust :: rust copy to clipboard 
Rust :: get os name rust 
Rust :: armanriazi•rust•syntax•names 
Rust :: rust•armanriazi•error•[E0382]: use of moved value: `counter` value moved into closure here, in previous iteration of loop 
Rust :: armanriazi•rust•error•[E0614]: cannot be dereferenced 
Rust :: armanriazi•rust•concept•dst•or•unsizedtype 
Rust :: rust how to make print happen before asking for input 
Lua :: roblox how to make a rainbow part 
ADD CONTENT
Topic
Content
Source link
Name
7+9 =