jeudi 7 avril 2022

Assign certain number of values to cells

I created a data frame with 20 observations, an extra column with all NAs. I'm wondering if there's a way to randomly assign for example 15 "YES" and 10 "NO" or randomly assign for example 15 "1" and 10 "0" for column "A". I would appreciate all the help there is. Thanks in advance!

dt <- data.frame(ID <- 1:20)
dt <- dt %>% 
  add_column(A = NA)%>%
  rename(ID = ID....1.20)



Aucun commentaire:

Enregistrer un commentaire