Hi, there. This is my issue.
I want to input a random number by a group.
if alc == grp1, then a value of a new variable, named 'alc_annual' , has to be random number between 24 and 36.
R code > tmp <- tmp %>% mutate(annual_alc = case_when(alc == 1 ~ 0 , alc == 2 ~ 0 , alc == 4 ~ 12, alc == 5 ~ runif(6876,24,36)[i], alc == 6 ~ runif(6876,48,56)[i], alc == 7 ~ runif(6876,104,156)[i], alc == 8 ~ runif(6876,330,366), TRUE ~ annual_alc))
But the problem is that when I run the above code, the whole data which 'alc==4' are input a same number.
I just need to make a different random number although they are in the same group.
I'll waiting for some advices and thanks for your considering.