0
ID            Error
EID0062, EID0175     1
EID0063              1
EID0063              1
EID0064              1
EID0069              1
EID0069              0
EID0072              0
EID0075              0
EID0075              0
EID0093              1
EID0023              0
EID0013              1
EID0062, EID0175     1

I have ~200 rows with ~150 unique IDs. I would like to create a new data.frame with just the unique IDs and have the column Error be representative if there is ever an error for that person. For example, for EID0069, there is both an error and non-error, but I would like the new df to show that person as an error. Like this:

ID            Error
EID0062, EID0175     1
EID0063              1
EID0064              1
EID0069              1
EID0072              0
EID0075              0
EID0093              1
EID0023              0
EID0013              1

All the best!

Evan
  • 1,477
  • 1
  • 17
  • 34
  • There are several questions with great answers about *"calculate ... per group"*, one such solution would be `aggregate(Error~ID, data=dat, FUN=max)`. There are several alternatives, please read the dupe-links (once it pops up). – r2evans Nov 30 '21 at 19:51
  • I chose `max` as the aggregating function since it seemed to fit your needs. It's also realistic to use an anonymous function, such as `aggregate(..., FUN = function(z) { ... })` where `z` is a vector of the values (LHS) within each group defined on the RHS of the `~`. – r2evans Nov 30 '21 at 20:13

0 Answers0