I have list of columns that I want to combine into a vector. The column element could be a name or the string "0". I would like to get a list of the column's elements that have a name into a character vector called df$keywords
. I have pasted an example dataframe below. I would like it to become
df$keywords[1,]
would be an empty vector
df$keywords[2,]
would be (ACT Science
, study skills
, MCAT
)
Any help would be appreciated
structure(list(V31 = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L), .Label = "0", class = "factor"), V32 = structure(c(1L,
2L, 4L, 5L, 7L, 8L, 6L, 5L, 3L, 3L), .Label = c("0", "ACT Science",
"English", "Microsoft PowerPoint", "physics", "proofreading",
"reading", "writing"), class = "factor"), V33 = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "0", class = "factor"),
V34 = structure(c(1L, 7L, 5L, 5L, 8L, 2L, 6L, 5L, 3L, 4L), .Label = c("0",
"geography", "Italian", "literature", "prealgebra", "SAT reading",
"study skills", "trigonometry"), class = "factor"), V35 = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "0", class = "factor"),
V36 = structure(c(1L, 3L, 4L, 4L, 7L, 2L, 6L, 4L, 5L, 5L), .Label = c("0",
"English", "MCAT", "precalculus", "proofreading", "SAT writing",
"writing"), class = "factor"), V37 = structure(c(1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "0", class = "factor"),
V38 = structure(c(1L, 1L, 5L, 5L, 2L, 1L, 4L, 5L, 3L, 6L), .Label = c("0",
"English", "GED", "physical science", "reading", "spelling"
), class = "factor")), .Names = c("V31", "V32", "V33", "V34",
"V35", "V36", "V37", "V38"), class = "data.frame", row.names = c(NA,
-10L))
vector
or into adata.frame
? Please consider revising your question for clarity.