Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I filter out participants with a bad score?

I want to filter out participants with that score less than 45% correct. I use a pipe to group by participants, and then try to filter like this:

# Remove participants with > 45% or more mistakes
  dat <- dat %>%
    group_by(participant) %>%
      filter(sum(key_resp.corr) < (nrow(dat) * 0.65))

Key_resp.corr is 1 when the participant gave a correct answer. Unfortuneatly this doesn’t seem to work. Anyone knows how I can make this work?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Instead of nrow(dat), it would be n(), which returns the number of rows of the grouped data, whereas nrow(dat) returns the number of rows of the whole dataset

library(dplyr)
dat %>%
    group_by(participant) %>%
    filter(sum(key_resp.corr, na.rm = TRUE) < (n() * 0.65)) %>%
    ungroup

Or create the filter with mean

dat %>%
   group_by(participant) %>%
   filter(mean(key_resp.corr, na.rm = TRUE) < 0.65) %>%
   ungroup
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading