0

I've looked everywhere here and here, but none of the answers match what I want. My question is like this.

what I want. My question is like this.

3xy : 2y

The answer I want is 3x/2

My attempt code is like this:

x <- 2/3
y <- x
cat("mark x:", x, "\n")
cat("mark y:", y, "\n")

Thank you, any answer would be appreciated.

Fahrizal
  • 47
  • 6
  • 1
    What you are describing is pretty far afield of what R was built for. There are "computer algebra system" packages that will mimic this type of functionality (i.e. Ryacas package), but most people simply do not use R for this, rather something like Mathematica. – joran Jun 26 '23 at 00:01

1 Answers1

3

With Ryacas you can do:

library(Ryacas)

yac_str("Simplify(3*x*y/(2*y))")
# "(3*x)/2"
Stéphane Laurent
  • 75,186
  • 15
  • 119
  • 225