I have data in untidy form. One of the columns contains combined information -
- section (a, b)
- question no. (1 or 01, 2 or 03, 3 or 03)
- the question (name, address, ...)
I wish to create a separate column for each.
Below is an example with the desired result.
library(tidyverse)
tbl <- tibble(
variable = c("a01_name", "a02_address", "a3_phone_number",
"b1a_total_income", "b01b_no_of_cars")
)
# desired result
desired_tbl <- tibble(
section = c("a", "a", "a", "b", "b"),
question_no = c(1, 2, 3, 1, 1),
sub_question_no = c(NA, NA, NA, "a", "b"),
question = c("name", "address", "phone_number", "total_income", "no_of_cars")
)