I have a dataset in a "long" format that I want to change to a "wide" format. I want to group by a set of columns and group the remaining columns into corresponding pairs. I think I know to how to long to wide when it is just one column being 'widened', but I can't get it to work when I need multiple long widened at the same time.
Please look at the examples for the desired starting and end point.
STARTING:
structure(list(gender = structure(c(2L, 2L, 2L, 1L, 1L, 1L, 2L
), .Label = c("female", "male"), class = "factor"), state = structure(c(3L,
3L, 3L, 1L, 1L, 1L, 2L), .Label = c("ca", "ny", "tx"), class = "factor"),
name = structure(c(3L, 5L, 7L, 6L, 1L, 2L, 4L), .Label = c("ashley",
"jackie", "john", "luke", "mark", "mary", "rob"), class = "factor"),
value = c(1L, 2L, 3L, 1L, 2L, 3L, 1L)), .Names = c("gender",
"state", "name", "value"), class = "data.frame", row.names = c(NA,
-7L))
ENDING:
structure(list(gender = structure(c(2L, 1L, 2L), .Label = c("female",
"male"), class = "factor"), state = structure(c(3L, 1L, 2L), .Label = c("ca",
"ny", "tx"), class = "factor"), value1 = c(1L, 1L, 1L), name1 = structure(c(1L,
3L, 2L), .Label = c("john", "luke", "mary"), class = "factor"),
value2 = c(2L, 2L, NA), name2 = structure(c(2L, 1L, NA), .Label = c("ashley",
"mark"), class = "factor"), value3 = c(3L, 3L, NA), name3 = structure(c(2L,
1L, NA), .Label = c("jackie", "rob"), class = "factor")), .Names = c("gender",
"state", "value1", "name1", "value2", "name2", "value3", "name3"
), class = "data.frame", row.names = c(NA, -3L))