Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 210
David Angyal Avatar asked Jan 11 '23 18:01

David Angyal


1 Answers

Use all.vars:

all.vars(e)
[1] "x" "y"
like image 90
James Avatar answered Jan 14 '23 07:01

James