How can I parse an R formula object (fo) correctly (i.e., not turning it into a string when parsing)?
Let's say I have the following:
## Creating a formula object
fo <- y ~ x1 + x2 | 0 + z1 + z2 + z3 + z4 + z5
class(fo)
##[1] "formula"
typeof(fo)
##[1] "language"
strsplit(fo, split='|', fixed=TRUE)
##Error in strsplit(fo, split = "|", fixed = TRUE) : non-character argument
Hopefully, I want to parse it into three atomic vectors:
- Dependent variable:
c("y"). - Regressors:
c("x1", "x2"). - Others:
c("z1", "z2", "z3", "z4", "z5")(excluding the0).