Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. df = structure(list(Group = c(1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3,
  2. 3), index = c(1, 2, 3, 4, 1, 2, 3, 4, 5, 6, 1, 2, 3)), row.names = c(NA,
  3. -13L), class = c("tbl_df", "tbl", "data.frame"))
  4.  
  5. df = structure(list(Group = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  6. 1, 1, 1, 1), index = c(1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4,
  7. 4, 4, 4)), row.names = c(NA, -16L), class = c("tbl_df", "tbl",
  8. "data.frame"))
  9.  
  10. df = structure(list(Group = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  11. 1, 1, 1, 1), index = c(1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1,
  12. 2, 3, 4)), row.names = c(NA, -16L), class = c("tbl_df", "tbl",
  13. "data.frame"))
  14.  
  15. library(dplyr)
  16.  
  17. df %>%
  18. group_by(Group) %>%
  19. slice(rep(seq_len(n()), each = n()))
  20.  
  21. df %>%
  22. group_by(Group) %>%
  23. slice(rep(seq_len(n()), n()))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement