[R] Splitting Numerical Vector Into Chunks

Sidoti, Salvatore A. sidoti.23 at buckeyemail.osu.edu
Wed Apr 20 15:40:13 CEST 2016


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)))

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

More information about the R-help mailing list