Edit: I could've asked this question better and as I was re-writing it multiple people provided good answers below. Stack etiquette is to not delete an answered question, so this post shall remain up.
So here is my "reprex":
inputs <- (12.8, 30, 10, 10.3, 3.1)
# I want a function to do the following
function(inputs)
# Output: 12.8 + 10 + 10.3 - 3.1 = 30
The tricky part is here is:
- I don't know what single number is going to be on the right of the equality.
- The only operations permitted are addition and subtraction.
The input vector will always be such that there is only one way to add/subtract numbers and come to a value that exists within the input.
I am flexible on how the output looks. Above is just an example.
solve()
and other systems of equations packages I have found thus far require me to determine one side of the equality in advance.