I'm using tidyverse to load the data, so I have a tibble which you can reproduce like:
df_1 <- tibble(id = c(1, 2, 3), subject_id = c("ABCD-FOO1-G001-YX-732E5", "ABCD-FOO2-A011-ZA-892N2", "ABCD-FOO3-1001-CD-742W5"))
Now I want to modify subject_id to extract just the two first character groups, i.e:
"ABCD-FOO1-G001-YX-732E5" -> "ABCD-FOO1"
When I'm running the following code:
df_1 %>% mutate(subject_id = stringr::str_match(subject_id, "[^-]*-[^-]*"))
each element of the subject_id column is a tibble itself:
> class(df_1[1, "subject_id"])
[1] "tbl_df" "tbl" "data.frame"
How do I make sure subject_id is a character vector instead of tibble?