I have a binary data frame like the following:
factor ID t1 t2 t3 t4 t5 t6 t7 t8 t9 t10
x1 a1 0 0 0 1 0 1 0 0 1 1
x2 a1 1 1 1 0 0 0 0 0 0 0
x3 a1 0 0 0 0 0 0 0 1 0 1
x1 a2 1 0 0 0 1 0 1 0 0 1
x2 a2 1 1 1 1 1 1 1 0 0 1
x3 a2 0 0 1 0 0 0 1 1 1 1
x1 a3 0 0 0 0 0 0 1 1 0 0
x2 a3 0 0 1 1 1 1 0 0 0 0
x3 a3 0 1 1 1 1 0 1 1 1 1
And I want to know for each factor and each ID when the first "1" occurred (which t). So the result would look like this:
factor ID t
x1 a1 t4
x2 a1 t1
x3 a1 t8
x1 a2 t1
x2 a2 t1
x3 a2 t3
x1 a3 t7
x2 a3 t3
x3 a3 t2
How do I write a code to obtain this in R? Thanks