Let's suppose I have the following data frame:
one = c(0, 2, 1, 3, 0, 5)
two = c(0, 2, 1, 3, 0, 0)
three = c(1, 0, 8, 0, 5, 0)
four = c(3, 0, 0, 7, 9, 0)
df <- data.frame(one, two, three, four)
df
For row 1: There is no column containing fulfilling the criteria (column contains a zero and is followed by only zeros) For row 2: It is column 3. because it contains a zero and is followed by zeros until the last column (until column 4) For row 3: It is column 4 For row 4: same as row 1 For row 5: same as row 1 and 4 For row 6: It is column 2 (because it contains the first 0 and is followed by only 0 until the last column)
I want my result to be an additional column to my dataset containing the month of churn
churn = ('','three','four','','','two')
My idea is to detect the column that contains a zero and check if the sum of the following columns would be zero