How to convert every % value with decimal in R programming?

 


We can use auxiliary function and mutate_if to achieve this output. Below is the code snippet:

is.percentage <- function(x) any(grepl("%$", x))

df1 %>%
  mutate_if(is.percentage, ~as.numeric(sub("%", "", .))/100)

 


Related #tags:     #r-programming     #function    

Related questions




Looking for change? Click below to prepare for technical interview.


Technical Interview Questions