Problem
I’m encountering the following error while using the create calculation:
Error in mutate(., Remainder = "Actual Value" - forecasted_value) :
ℹ In argument: `Remainder = "Actual Value" - forecasted_value`.
Caused by error in `"Actual Value" - forecasted_value`:
! non-numeric argument to binary operator
The issue occurs when I try to create a new column Remainder
by subtracting forecasted_value
from "Actual Value"
. The error message indicates that there’s a problem with using a non-numeric argument in a binary operation (-
).
Solution
The problem is due to "Actual Sales"
being treated as a character string (a literal), not as a column name in the data frame. In R, enclosing something in double quotes makes it a character, not a variable or column reference.
To reference a column with spaces in its name, you should use backticks instead of quotes. Here’s the corrected code:
`Actual Value` - forecasted_value
Using backticks tells R to interpret Actual Sales
as the column name rather than a string. Make sure both Actual Value
and forecasted_value
are numeric; otherwise, you might run into the same error due to data types.