The suggested solution is working general, but doesn't solve one of the goals: to be able to select dynamically a column, because the matches() expects a character vector.
Continuing on your idea, the following can be a solution:
library(tidyverse)
floor_if_not_missing <- function(df, col_name){
col_name <- rlang::as_label(rlang::enquo(col_name))
df %>% mutate(across(matches(col_name), floor))
}
mtcars %>% head(3) %>% floor_if_not_missing(mpg)
#> mpg cyl disp hp drat wt qsec vs am gear carb
#> Mazda RX4 21 6 160 110 3.90 2.620 16.46 0 1 4 4
#> Mazda RX4 Wag 21 6 160 110 3.90 2.875 17.02 0 1 4 4
#> Datsun 710 22 4 108 93 3.85 2.320 18.61 1 1 4 1
mtcars %>% head(3) %>% floor_if_not_missing(miles_per_gallon)
#> mpg cyl disp hp drat wt qsec vs am gear carb
#> Mazda RX4 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4
#> Mazda RX4 Wag 21.0 6 160 110 3.90 2.875 17.02 0 1 4 4
#> Datsun 710 22.8 4 108 93 3.85 2.320 18.61 1 1 4 1
Any other improvement (simplification) idea?