I have an R data frame which is just 1 row and looks like so:
x1 x2 x3 x4 x5 x6 x7 x8 x9 x10
1 1 1 1 0 1 0 1 0 0
I want to know how many 1s there are in a row starting from the first position. So this would be 4.
More examples:
(Example 1)
x1 x2 x3 x4 x5 x6 x7 x8 x9 x10
0 1 1 1 0 1 0 1 0 0
would be 0 because the first position isn't even a 1.
(Example 2)
x1 x2 x3 x4 x5 x6 x7 x8 x9 x10
1 0 1 1 0 1 0 1 0 0
would be 1.
How can I implement this?
numInStreakAtBeginning = function(row) {
}
Additionally, how can I implement a method that looks for the largest streak regardless of where it starts? For example,
x1 x2 x3 x4 x5 x6 x7 x8 x9 x10
1 0 1 1 1 1 0 1 0 0
would be 3.