Skip to content
Prev 360275 / 398503 Next

Splitting Numerical Vector Into Chunks

Greetings!

I have several large data sets of animal movements. Their pauses (zero magnitude vectors) are of particular interest in addition to the speed distributions that precede the periods of rest. Here is an example of the kind of data I am interested in analyzing:

x <- abs(c(rnorm(2),replicate(3,0),rnorm(4),replicate(5,0),rnorm(6),replicate(7,0)))
length(x)

This example has 27 elements with strings of zeroes (pauses) situated among the speed values.
Is there a way to split the vector into zero and nonzero chunks and store them in a form where they can be analyzed? I have tried various forms of split() to no avail.

Thank you!
Salvatore A. Sidoti