I have a two column dataset from a survey, the first column the question and the second the response. Many of the question names represent the two parts of the question - the main topic of the question (in the reprex, "JobFactor" and "WorkChallenge") and then the specific job factor or work challenge that question is asking (e.g. "Diversity", "Remote", etc.).
I'd like to split those two parts into two different columns (see desired_df). In good news, all the words in the question are noted with a capital; on the other hand, the word length of the two parts varies, so I can't just extract the first two words from each.
library(tibble)
#> Warning: package 'tibble' was built under R version 3.4.1
original_df <- tribble(
~variable, ~response,
"JobFactorDiversity", "Important",
"JobFactorRemote", "Not Important",
"JobFactorDiversity", "Not Important",
"WorkChallengeFrequency", "Frequent",
"WorkChallengeDirtyData", "Rarely"
)
desired_df <- tribble(
~factor, ~aspect, ~response,
"JobFactor", "Diversity", "Important",
"JobFactor", "Remote", "Not Important",
"JobFactor", "Diversity", "Not Important",
"WorkChallenge", "Frequency", "Frequent",
"WorkChallenge", "DirtyData", "Rarely"
)