Table of contents
Hide
Sum two variables
For whatever reason, if you sum two variables var1
and var2
from df
, you might get the following error: Non-numeric argument to binary operator
.
To circumvent it, just be sure that both variables are numeric within the sum:
df$var3 <- as.numeric(as.character(df$var1)) + as.numeric(as.character(df$var2))
By “within the sum”, I mean you need to write this in one single line. If you break it in two or three lines, it won’t work ¯\_(ツ)_/¯