Guest User

Untitled

a guest
Jul 17th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. age X1 X2
  2. age 0 2 2
  3. age 1 2 2
  4. age 2 2 3
  5. ...
  6.  
  7. age 0 age 1 age 2
  8. X1 2 2 2
  9. X2 2 2 3
  10. ...
  11.  
  12. data <-structure(list(age = c("age 0", "age 1", "age 2", "age 3", "age 4",
  13. "age 5", "age 6", "age 7", "age 8", "age 9", "age 10", "age 11",
  14. "age 12"), X1 = c(2, 2, 2, 4, 7, 12, 19, 22, 18, 11, 6, 3, 3),
  15. X2 = c(2, 2, 3, 4, 8, 14, 21, 24, 20, 12, 7, 4, 3)), row.names = c("0",
  16. "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"
  17. ), class = "data.frame")
  18.  
  19. library(tidyr)
  20. wide <- spread(data, age, X1)
  21. #X2 remains the same, and X1 is not correcty reshaped.
  22. wide <- spread(data, age, X1, X2)
  23. #Error in spread.data.frame(data, age, X1, X2) : object 'X2' not found
Add Comment
Please, Sign In to add comment