0

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

MrFlick
  • 195,160
  • 17
  • 277
  • 295
  • 2
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. What type of object is `test` and what does it contain? – MrFlick Nov 30 '22 at 14:50

0 Answers0