I am developing a sensor dependent variable for use in survival analysis. My goal is to find the last time ("time") that a person answered a question in a survey (for example, where "q.time" is "1", and "q.time + 1" and q Is coded in) the later time is coded as "0") By this argument, the last question answered is coded as "1" (q.time) should be done. The first question that has not been answered (q.time + 1) should be coded as "0" and all the questions after answering the first question should be coded as "NA". I want to remove all the rows where my dataset from DV = NA A very generous colleague has helped me develop the following code, but she is now on leave and she needs a little more lovin. The code is as follows: Library (plyr) #ddply for the library (statistics) # to resize (...) # from the above data & lt; - data.frame (id = c (1, 2, 3, 4), q.1 = c (1, 1, 0, 0), q.2 = c (1, 0, 1, 0), d...