4

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?

1
  • You'd be slightly better off creating the simpler call object here: e <- quote(2 * x^2 + y) Commented Dec 3, 2013 at 16:19

1 Answer 1

9

Use all.vars:

all.vars(e)
[1] "x" "y"
Sign up to request clarification or add additional context in comments.

1 Comment

And in case you want to write variations, adv-r.had.co.nz/… describes how to do it with recursive R code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.