Pass fail test by group

Colleagues,

Here is my data set.

Capture2

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.

library(tidyverse)
# start making example data
set.seed(42)
example_data <- tibble( serial = sample.int(5,size = 15, replace=TRUE),
                        measurement = sample.int(200,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"),
                                                                    "fail","pass"))
#connect the group outcome back to the original data
example_data2 <- left_join(example_data,
                           serial.test)

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

dput(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.