Exclude some participants

Hey together,

I have a question. In my sample, I would like to exclude some subjects from the evaluation who have not answered the control question correctly. Therefore I have a column "wrong answers" in my data set, where 0 or 1 is written. I would like to exclude all subjects who answered the control question incorrectly (=1).

Can you help me, how can i do it?

Thank you!

Could you share a small sample of your data? wrong answers isn't common variable name. How you filter out some of the subjects may vary slightly based on the data structures you are using as well.

Thanks. Using this data frame

dframe <- 
  data.frame(
    Subject_Number = 1:10, 
    gender = c("female", "male", "female", "female", "female", 
               "female", "male", "female", "male", "male"), 
    wrong_answers = c(0, 1, 0, 0, 0, 0, 1, 0, 0, 1),
    stringsAsFactors = FALSE
  )

You can do this with either

AnsweredCorrectly <- dframe[dframe$wrong_answers == 1, ]

or if you prefer dplyr syntax

library(dplyr)
AnsweredCorrectly <- 
  filter(dframe, 
         wrong_answers == 1)

unrelated note
As a note in case you need help in the future, one way to make it easier to help is to give us code that generates your sample data. head and dput are functions that are really helpful for that. For instance,

dput(head(dframe, 10))

Perfect, thank you very much!

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.