I have a dataset
structure(list(group = c("A", "B", "A", "B", "B", "A", "A"),
technique = c("attack", "defenese", "attack ", "defense ",
"defense ", "attack", "defense "), outcome1.part1 = c(24L,
1234L, 15L, 234L, 23L, 3L, 3L), outcome1.part.2 = c(52L,
321L, 23L, 234L, 234L, 145L, 145L), outcome1.part.3 = c(14L,
23L, 3L, 2L, 234L, 234L, 234L), outcome2.part.1 = c(14L,
234L, 145L, 4L, 234L, 145L, 145L), outcome2.part.2 = c(234L,
234L, 234L, 234L, 234L, 234L, 234L), outcome2.part.3 = c(234L,
234L, 234L, 234L, 145L, 145L, 145L)), class = "data.frame", row.names = c(NA,
-7L))
Dataset needs to be converted to long form but I want to make a vector that looks for any phrase from a specified key and then decides what level of a grouping variable will be assigned.
So say in column outcome1.part.2 I want to convert this to long form and create a column called strata that uses whatever value from a key is found inside the column name. So the key would be c("part.1", "part.2", "part.3") and it will convert a row like this.
to this
I do not want to use regex solutions because I want to flexibly change the values in the key without figuring out a new regex solution for every level of the grouping variable.

