If I run a sum function and explicitly call the named column I have no problem. But if I try to build the reference out of a passed character vector I get this error.
All the answers to this error I can find talk about characters in the column itself, which is not my problem. It runs fine if I type it out. I think if has something to do with $
.
Thanks in advance.
pollut<-"nitrate"
> sum(test1$nitrate, na.rm=TRUE)
[1] 67.089
> sum(paste("test1$",pollut,sep=""), na.rm=TRUE)
Error in sum(paste("test1$", pollut, sep = ""), na.rm = TRUE) : invalid 'type' (character) of argument
Edit...A suggested answer did identify the problem but not the solution as Richard so clearly did.