Pass fail test by group


Here is my data set.


Each serial number has an associated measurement.
Each measurement is tested to determine if it is less than or equal to 16. This is easy to code using R.

What is less apparent is how to code the serial.test result.

The serial.test result will fail if any one of the measurements associated with that serial number is greater than 16.

I need the serial.test result because I want to create a box plot of the measurements by serial number to help the user see which serial numbers are passing or failing.

# start making example data
example_data <- tibble( serial =,size = 15, replace=TRUE),
                        measurement =,size=15,replace=TRUE) /10)  %>% arrange(serial) %>%
  mutate(mlte16 = ifelse(measurement > 16 , 'fail','pass'))
#finish example data

#calculate the group outcome
serial.test <- group_by(example_data,
                           serial) %>% summarise(serial.test=ifelse(max(mlte16=="fail"),
#connect the group outcome back to the original data
example_data2 <- left_join(example_data,

Hi, and welcome!

Please see the FAQ: What's a reproducible example (`reprex`) and how do I do one? Using a reprex, complete with representative data will attract quicker and more answers. In this case, without the data to play with, it's hard to give more than general guidance.

Since all that's needed is the data, assuming you have a data frame dat


and cut and paste the result.

Chaining this should work similarly to

dat %>% 
    filter(measurement.lte.16 == "pass") %>%
    group_by(serial) %>%
    summarize(sum(measurement.lte.16) -> serial.fails

This is, of course, not debugged, for want of data, but should get you started.

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