I have a data.frame like
a b c d
1 1 0 0 1
2 1 1 0 0
3 0 1 0 0
4 1 0 1 0
5 1 0 0 0
Which I generated using
df<- data.frame(a=sample(0:1,5,replace=T),b=sample(0:1,5,replace=T),c=sample(0:1,5,replace=T),d=sample(0:1,5,replace=T))
How can I get the result as 4, 2, 2, 3, 1 if I pass 1 to that function depicting to find the last index of 1 in each row.