I need to calculate (in R) the number of positive and negative runs in a vector. For example, suppose I have a vector x :
x = c(-23 , -2 , 5 , 8, 9, 12, -2, -1, 3, 5, 7)
than the number of runs is four, since I have: {-23, -2}, {5,8,9,12}, {-2, -1} and {3,5,7}. Thus, basically every time a series changes sign, it is considered equal to +1 in the run counter.
jeremy.staub
source share