I have a data frame in R which is grouped by id. The column "value3" always has positive values. I would like to obtain the first row in which one of the other columns has non-zero entries for each id.
For instance:
Given the following data set
structure(list(id = c(1, 1, 1, 4, 4, 4, 4, 6, 6, 6), value1 = c(0,10, 10, 0, 20, 20, 8, 0, 10, 10), value2 = c(0, 30, 10, 0, 0,0, 10, 20, 20, 15), value3 = c(10, 10, 10, 10, 10, 10, 10, 10,10, 10)), class= "data.frame", row.names = c(NA, -10L))
the desired result would be
structure(list(resid = c(1, 4, 6), resvalue1 = c(10, 20, 0),resvalue2 = c(30, 0, 20), resvalue3 = c(10, 10, 10)), class = "data.frame", row.names = c(NA,-3L))
I have been using dplyr to slice and select, but I cannot figure out this particular problem. Any help is appreciated.