Making tidyeval function inside case_when
问题 I have a data set that I like to impute one value among others based on probability distribution of those values. Let make some reproducible example first library(tidyverse) library(janitor) dummy1 <- runif(5000, 0, 1) dummy11 <- case_when( dummy1 < 0.776 ~ 1, dummy1 < 0.776 + 0.124 ~ 2, TRUE ~ 5) df1 <- tibble(q1 = dummy11) here is the output: df1 %>% tabyl(q1) q1 n percent 1 3888 0.7776 2 605 0.1210 5 507 0.1014 I used mutate and sample to share value= 5 among value 1 and 2 like this: df1 %