user3090164
user3090164

Reputation: 65

How to calculate in R with variables

I'm a R newbie.

is there a way i can calculate

(x+x^2+x^3)^2

in R?

so i will get the result:

x^6+2 x^5+3 x^4+2 x^3+x^2

I get an Error: object 'x' not found.

Thanks!

Upvotes: 1

Views: 158

Answers (1)

Michael Veale
Michael Veale

Reputation: 959

R isn't well suited for this. Some interface packages to languages and libraries that are better at this do exist, such as rSymPy, which allows you to access the SymPy Python library for symbolic mathematics (you'll need to install both). In a similar vein, Ryacas links to the yacas algebra system.

Those interfaces are useful if you need symbolic manipulation as part of an R workflow. Otherwise, consider using the original tools. The ones above are open source and freely available, while other free use alternatives also exist, such as the proprietary web based Wolfram Alpha (for limited use).

Upvotes: 3

Related Questions