Skip to content

Instantly share code, notes, and snippets.

@benjamin-chan
Last active January 27, 2022 16:30
Show Gist options
  • Save benjamin-chan/7936b2b56dc0778c42913577f07ed5cf to your computer and use it in GitHub Desktop.
Save benjamin-chan/7936b2b56dc0778c42913577f07ed5cf to your computer and use it in GitHub Desktop.
Random sample
library(magrittr)
library(dplyr)
c("Alice",
"Bob",
"Carol",
"Dave") %>%
unique() %>%
sample(1e6, replace = TRUE) %>%
data.frame(names = .) %>%
group_by(names) %>%
summarize(freq = n()) %>%
ungroup() %>%
mutate(total = sum(freq)) %>%
mutate(rank = rank(freq %>% desc())) %>%
mutate(timestamp = Sys.time()) %>%
arrange(rank) %>%
write.csv("randomDraw.csv", row.names = FALSE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment