Advertisement
Guest User

Untitled

a guest
Jul 15th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 0.40 KB | None | 0 0
  1. id <- 1:80000
  2. N = 80000
  3. group <- rep(1:8, each = 10000)
  4. group_selection_probability <- c(0.4,0.3,0.15,0.05,0.04,0.03,0.02,0.01)
  5. group_selection_probability <- rep(group_selection_probability, each = 10000)
  6. weight <- (group_selection_probability/sum(group_selection_probability))*N
  7. data <- data.frame(id,group,weight)
  8. sample <- dplyr::sample_n(data, size = 1000, weight = weight)
  9. table(sample$group)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement