I want to make a simple script where I'll sum some variables according to a fixed naming scheme. But the problem is, not all variables will be used every time. But if I try something like this:
result <- sum(variable1, variable2, variable3, na.rm = TRUE)
I get an error saying there's no variable1
. Is there a way to sum only the existing variables and ignore the non-existing ones without declaring all possible variables as NA beforehand?