Home > Mobile >  Perform test in R to check if all tests are present for every 35-37 rows of dataset
Perform test in R to check if all tests are present for every 35-37 rows of dataset

Time:11-18

I have a dataset which contains around 35-37 tests for each participant. Something like this:

Participant_ID Test_ID
71822 2125
71822 2167
71822 2145
71822 2189
71822 2143

The data contains 35-37 rows of for each participant and their respective test results.

I want to automatize this task where I can check if the test for any participant is less than 35 then it should say False otherwise True.

I tried to do following to check if at least following tests are present for each particiapant

test_ID <-   c("2125", "2167", "2145", "2189", "2143")

  dat %>% 
  group_by(Paticipant_ID) %>% 
  test_ID %in% as.matrix(dat$Test_ID)

CodePudding user response:

To test how many rows there are per participant:

library(tidyverse)
data %>% group_by(Participant_ID) %>% count()

to show which combinations are missing:

# get a list of every combination of participant and test
allOptions <- expand.grid(unique(data$Participant_ID), unique(data$Test_ID))
names(allOptions) <- names(data)
# look for missing ones
anti_join(allOptions, data)
  • Related