Hi Guys,
I am looking for a help to get consecutive positive and negative numbers on these lines.
columns : M-1 to M-6
In first row,you can see there are 2 consecutive +ve's and corresponding result needs to be calculated in Consecutive +ve column and vice versa. I tried using dpylr, but i was not able to formulate for all these rows(which is a part of a much bigger data set), many of the queries which got answered in respective forums were actioning only 1 column i.e checking results for "M-6" column alone. Please help me out.
Can this be done with the help of a for and if else loop as well?
M-6 | M-5 | M-4 | M-3 | M-2 | M-1 | Consecutive+ve | Consecutive -ve |
---|---|---|---|---|---|---|---|
1 | 1 | 0 | 0 | 0 | 1 | 2 | 0 |
4 | -4 | 0 | 0 | 10 | 10 | 2 | 0 |
0 | 0 | 1 | 1 | 1 | 0 | 3 | 0 |
5 | 0 | 1 | 1 | 1 | 1 | 4 | 0 |
-1 | -1 | 1 | 1 | 1 | 1 | 4 | 2 |
0 | 0 | 0 | 0 | 0 | 24 | 0 | 0 |
0 | 0 | 0 | 0 | 0 | 2 | 0 | 0 |
3 | 0 | 0 | 2 | 0 | 2 | 0 | 0 |
0 | -1 | 0 | 1 | 1 | 1 | 3 | 0 |
3 | 0 | 0 | 0 | 0 | 2 | 0 | 0 |
-4 | 6 | -3 | 5 | 8 | 2 | 3 | 0 |
-72 | -27 | -10 | 13 | 42 | 7 | 3 | 3 |