I have a tibble similar to this, but with many more columns:
Bead_003_normalized | Bead_003_serology | Bead_003_CI | Bead_003_result | Bead_004_normalized | Bead_004_serology | Bead_004_CI | Bead_004_result | A2_result | A*02:01_result | A*02:03_result |
---|---|---|---|---|---|---|---|---|---|---|
5000 | A2 | A*02:01 | NA | 7000 | A2 | A*02:03 | NA | TRUE | FALSE | FALSE |
1200 | A2 | A*02:03 | NA | 500 | A2 | A*02:06 | NA | FALSE | FALSE | TRUE |
9000 | A2 | A*02:01 | NA | 500 | A2 | A*02:06 | NA | FALSE | TRUE | FLASE |
The set of columns on the left are information about individual beads in a lab test, with 4 columns of values per bead. The last three columns on the right are results of manual analysis of the test.
I want to write a function that will assign positive/negative to the "Bead_XXX_result" columns based on the value in the "AXX_result" columns. My intended result for this example would be this:
Bead_003_normalized | Bead_003_serology | Bead_003_CI | Bead_003_result | Bead_004_normalized | Bead_004_serology | Bead_004_CI | Bead_004_result | A2_result | A*02:01_result | A*02:03_result |
---|---|---|---|---|---|---|---|---|---|---|
5000 | A2 | A*02:01 | positive | 7000 | A2 | A*02:03 | positive | TRUE | FALSE | FALSE |
1200 | A2 | A*02:03 | positive | 500 | A2 | A*02:06 | NA | FALSE | FALSE | TRUE |
9000 | A2 | A*02:01 | positive | 500 | A2 | A*02:06 | NA | FALSE | TRUE | FLASE |
Essentially, whenever there is a TRUE value in one of the AXX_result columns, I want the function to search for the character string of the column name in any of multiple columns grouped by bead (I could certainly remove the "_result" from the names of last three columns if that would make it easier). It seems creating a nested table, with groups based on bead, is the way to go, and then maybe using something from the purrr package, but I'm not sure how to set it up.