Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR R

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)
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #multiple #columns
ADD COMMENT
Topic
Name
1+3 =