R – Exclude entire subjects if they lack data in one condition

You may also like...

1 Response

  1. Your code max(agg_conditions$cond) assumes that at least one participant has data from all the combinations of conditions, no?;-)

    I was recently trying to do something similar using tidyverse:
    #Assumes S, block, error are factors

    exclude <- agg %>% group_by(S, block, error) %>% summarize(N=n()) %>% complete(block, error) %>% ungroup() %>% filter(is.na(N)) %>% select(S) %>% unique()

    Not sure it will work universally, or that it is the most elegant solution..

    I am also struggling with the actual exclusion of rows where S is in exclude, if I use S as factor (which makes sense, it is not a numeric variable), because the %in% comparison can compare the underlying factor values instead of factor labels.. Then one has to do something ugly like:

    agg.selected % filter(!(as.numeric(labels(S))[S] %in% exclude))

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.