Since your question is phrased concerning your error message and not whatever your function is attempting to achieve, I will address the error.
- is the 'binary operator' your error is referencing, and either
MA (or both) are non-numeric.
A binary operation is a calculation that takes two values (operands) and produces another value (view wikipedia for more).
+ is one such operator: "1 + 1" takes two operands (1 and 1) and produces another value (2). Note that the created value isn't necessarily diverse from the operands (e.g., 1 + 0 = 1).
R only knows how to execute
+ (and other binary operators, such as
-) to numeric arguments:
> 1 + 1
> 1 + 'one'
Error in 1 + "one" : non-numeric argument to binary operator
At the time you view that error message, it implies that you are (or the function you're calling is) attempting to readact a binary operation with something that isn't a number.
Your error lies in the use of
[ instead of
Day is a list, subsetting with
[ will return a list, not a numeric vector.
[[, but, returns an object of the class of the item seized in the list:
> Day <- Transaction(1, 2)["b"]
> Day + 1
Error in Day + 1 : non-numeric argument to binary operator
> Day2 <- Transaction(1, 2)[["b"]]
> Day2 + 1
Transaction, as you've identify it, returns a list of two vectors. Above,
Day is a list comprise one vector.
Day2, but, is easily a vector.