Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. df = data.frame(id = c(1,1,2,2,3,3,3,4,4,4,4,4),
  2. points = c(0,1,0,1,0,1,2,0,1,2,3,4),
  3. step = c(0, 0, 0, 0, 0.0000, -1.9701, -1.6758, 0.0000, -2.5414,-2.5397,1.1516, 3.9296))
  4.  
  5. id points step
  6. 1 1 0 0.0000
  7. 2 1 1 0.0000
  8. 3 2 0 0.0000
  9. 4 2 1 0.0000
  10. 5 3 0 0.0000
  11. 6 3 1 -1.9701
  12. 7 3 2 -1.6758
  13. 8 4 0 0.0000
  14. 9 4 1 -2.5414
  15. 10 4 2 -2.5397
  16. 11 4 3 1.1516
  17. 12 4 4 3.9296
  18.  
  19. id step0 step1 step2 step3 step4
  20. 1 1 0 0.0000 NA NA NA
  21. 2 2 0 0.0000 NA NA NA
  22. 3 3 0 -1.9701 -1.6758 NA NA
  23. 4 4 0 -2.5414 -2.5397 1.1516 3.9296
  24.  
  25. library(tidyverse)
  26. df %>%
  27. mutate(points = str_c("step", points)) %>%
  28. spread(points, step)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement