Rstudent
Rstudent

Reputation: 75

R - removing rows where values of one column fail to match another column

I have a line of code in my R script which calculates a percentage from my dataset edata regarding how often the values of two columns GazeCueTarget.CRESP and GazeCueTarget.RESP match up per row of data.

I want to be able to delete all the rows where the values from both of these columns do not match up. So if my below code tells me 97% of the time the values of GazeCueTarget.CRESP match that of GazeCueTarget.RESP on a given row of my data, I want to be able to get rid of the remaining 3% where the values mismatch.

This is what I have produced to give me a percentage for when the rows match up. Any advice would be very much appreciated. I think the solution should be quite simple but I am not sure.

paste0((100*with(edata, mean(GazeCueTarget.CRESP==GazeCueTarget.RESP, na.rm = "TRUE"))), "%")

Upvotes: 1

Views: 765

Answers (1)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 522817

You can try subsetting off non matching rows:

edata <- edata[edata$GazeCueTarget.CRESP == edata$GazeCueTarget.RESP, ]

Upvotes: 2

Related Questions