Skip to content
Prev 320277 / 398506 Next

Newbie code to count runs of up or down moves

Hi

slightly better, the error messages are starting from

                     if ((x[j] * x[j-1] < 0){
                       ^^^^
one parentheses more here

However R is not C and using built in functions is preferable to programming your own.

Just as a guess isn't combination of sign and rle what you want?
[1] -1  1  1 -1 -1 -1  1  1  1
Run Length Encoding
  lengths: int [1:4] 1 2 3 3
  values : num [1:4] -1 1 -1 1

Regards
Petr