jeudi 13 avril 2023

Replace NA value with a bunch of randomly generated values in R

I want to filter my Title column and then replace the NA values in Age column with a bunch of randomly generated values(within min and max age range). I tried the following command

titanic_df4 <- titanic_df3 %>% filter(titanic_df3$Title=='Mr.') %>% mutate(Age = replace_na(Age, runif(1, min=14, max=57)))

but it just replace the na value with one specific value within the range. What should I do?

Tried this

titanic_df4 <- titanic_df3 %>% filter(titanic_df3$Title=='Mr.') %>% mutate(Age = replace_na(Age, runif(1, min=14, max=57)))



Aucun commentaire:

Enregistrer un commentaire