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