I have a data frame containing two columns of identifying information and one column of letter pairs separated by a hyphen:
df<-data.frame(
list = rep(1:3, each = 2),
set = rep(c("A","B"), times = 3),
item = c("ab-cd","ef-gh","ij-kl","mn-op","qr-st","uv-wx")
)
What I'm trying to accomplish is converting a data frame into the following form, in which: 1. The individual lines indexed by the "list" are collapsed into one line each; 2. The column "item" is divided into adjacent columns with a hyphen as a separator; 3. The "set" column, which serves as the basis for naming the resulting columns.
df2 <- data.frame(
list = c(1:3),
A_1 = c("ab", "ij", "qr"),
A_2 = c("cd", "kl", "st"),
B_1 = c("ef", "mn", "uv"),
B_2 = c("gh", "op", "wx"))
( []) , BASE, reshape splitstackshape. , , .
, .