I have been trying to run the below code in R studio, it keeps giving non-numeric argument to mathematical function error message. Can someone help check the code below and guide me on how to get it sorted
gain=rep(999,nrow(test))
mise=1
a=predtest
b=test$res
for(i in 1:nrow(test)){
if(a[i]==b[i]&&b[i]==1&&same[i]==0){
gain[i]=(test[i,"PSJ1"]-1)*mise
}
else if(a[i]==b[i]&&b[i]==1&&same[i]==1){
gain[i]=0
}
else if(a[i]==b[i]&&b[i]==2&&same[i]==0){
gain[i]=(test[i,"PSJ2"]-1)*mise
}
else if(a[i]==b[i]&&b[i]==2&&same[i]==1){
gain[i]=0
}
else if(a[i]!=b[i]&&same[i]==1){
gain[i]=0
}
else if(a[i]!=b[i]&&same[i]==0){
gain[i]=-mise
}
}
round(gain, 2)
sum(gain)
I was expecting the receiv series of numbers containing gains value