Reputation: 155
I have data in the following format:
what I want to do is check in each row whether the value in pred is = to the one in obs
so in the example above 3 out of 5 are equal and the accuracy would be 60% ?
How can I do that?
Screenshot of code:
Upvotes: 0
Views: 4035
Reputation: 1162
It looks like your data frame is called "prediction".
The ==
operation takes each element if the vectors are of equal lengths and compares them, returning a TRUE or FALSE. When performing arithmetic on TRUEs and FALSEs they're treated like 1s and 0s respectively. As such the mean of this ==
comparison will give you what you want.
mean(prediction[["pred"]]==prediction[["obs"]])
Upvotes: 1