Description Usage Arguments Details Value Author(s) Examples
Get x
, y
, weight
, series
from a formula expression.
If expr
cannot be interpreted as formula, it will be returned as a character
vector as-is.
1 2 3 | getVarsFromFormula(expr, ...)
parse_formula(expr, ...)
|
expr |
An expression to coerce to formula. |
... |
Other arguments to pass to the function. |
There are two forms of arguments:
Put all the arguments in expr
and ignore ...
, then the function
will analyze the format and parse elements automatically: left-hand side to "~" is
y
, right-hand side to "~" is independent variables, of which symbols
connected with + or - is x
, symbols to the right of * is weight
and symbols to the right of | is series
.
Put arguments along with expr
and ...
, then the function
will wrap them up as-is and output in a named vector. In this case, the result
totally depends on the order you input the arguments.
If the parsing succeeds, then a named vector of x, y, series
and
weight
, the missing element will be output as NA
If the parsing fails, then the expr
as a character
If expr
is NULL or NA/NaN, then NULL or NA
If more than one asterisks or pipes are detected, the function will only extract the last match as series or weight.
Yiying Wang, wangy@aetna.com
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | ## Not run:
## Identify ingredients in a formula.
getVarsFromFormula("y+z~x*w+m|d") ## return
\tabular(cccc){
x \tab y \tab series \tab weight \cr
"x + m" \tab "y + z" \tab "d" \tab "w"
}
## it is equivalent to
parse_formula(y+z~x*w+m|d)
## another form
parse_formula(y+z, x+m, d, w)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.