Answers for "round multiple columns in r"

R
0

round multiple columns in r

# load dplyr
library(dplyr)

# Round at first decimal with a mixed df
mydf %>% mutate(across(where(is.numeric), round, 1))

# The two solutions above do the same
mydf %>% mutate(across(where(is.numeric), ~round(., 1)))
mydf %>% mutate_if(is.numeric, round, 1)
Posted by: Guest on January-25-2021

Browse Popular Code Answers by Language