Мы можем изменить функцию для оценки 'x', 'y' и выполнить присвоение :=
для создания столбца
library(dplyr)
library(magrittr)
ynf <- function(x, y) {
df %<>%
mutate(!! enquo(x) := case_when(
{{y}} == 0 ~ "No",
{{y}} == 1 ~ "Yes"
))
}
df <- ynf(weight_loss, `weight loss (dich)`)
glimpse(df)
#Rows: 20
#Columns: 2
#$ `weight loss (dich)` <int> 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1
#$ weight_loss <chr> "No", "No", "Yes", "No", "Yes", "No", "No", "Yes", "Yes", "Yes", "Yes", "No",…
data
set.seed(24)
df <- data.frame(`weight loss (dich)` = sample(0:1, 20, replace = TRUE),
check.names = FALSE)