I have a vector where each element is a string. I only want to keep the part of the string right before the '==' regardless of whether it is at the beginning of the string, after the & symbol, or after the | symbol. Here is my data:
data <- c("name=='John'", "name=='David'&age=='50'|job=='Doctor'&city=='Liverpool'",
"job=='engineer'&name=='Andrew'",
"city=='Manchester'", "age=='40'&city=='London'"
)
My ideal format would be something like this:
[1] "name"
[2] "name" "age" "job" "city"
[3] "job" "name"
[4] "city"
[5] "age" "city"
The closest I have got is using genXtract from the qdap library, which puts the data in the format above, but I only know how to use it with one condition, i.e.
qdap::genXtract(data, "&", "==")
But I don't just want the part of the string between & and == but also between | and == or the beginning of the string and ==