David Angyal
David Angyal

Reputation: 241

R expression variable list

Is it possible to get a vector or list of variables in an expression?

For instance:

e <- expression(2 * x^2 + y)

The desired output:

('x', 'y')

Is it possible? Or is it necessary to input variable names manually?

Upvotes: 4

Views: 333

Answers (1)

James
James

Reputation: 66844

Use all.vars:

all.vars(e)
[1] "x" "y"

Upvotes: 9

Related Questions