a <- data.frame(a=c("1","2","3"),b=c("1","2","3"))
apply(a,1,function(x) {
x["a"]<- as.numeric(x["a"])
x["b"]<- as.numeric(x["b"])
return(x["a"]+x["b"])
})
Why am I getting
Error in x["a"] + x["b"] : non-numeric argument to binary operator
?
Can I not modify values from within the apply
loop ?