0

I'm trying to solve the following equation in R for x:

(z + x)/y = remainder of zero

In other words, I'm trying to find what value should be added to my number "z" so that it divided by "y" gives a remainder of zero. I couldn't find anything about it so any help would be appreciated!

rebeca
  • 153
  • 1
  • 3
  • 8
  • 2
    I think you want the modulus operator `%%`. When asking for help, you should include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Jul 16 '18 at 14:19
  • `y <- 7; z <- 3; remainder <- 0; x <- 1:100; x[(z+x)%%y == remainder]` – jogo Jul 16 '18 at 14:24

2 Answers2

1

Since you are referring to a "remainder", I assume you are only dealing with integers.

z <- 8
y <- 7

(x <- ceiling(z / y) * y - z)
#[1] 6

(z + x) %% y
#[1] 0
Roland
  • 127,288
  • 10
  • 191
  • 288
-1

It's not the most optimised way but you can do this :

X,Y in R*
X*Y = S
S-X = Z

With this exept mistake from me your equation will alway give a remainder of zero

T.Gerard
  • 51
  • 5