Skip to content
Back to formatted view

Raw Message

Message-ID: <CY1PR0101MB10046C9003C13DD9FCAD4B3FAB6D0@CY1PR0101MB1004.prod.exchangelabs.com>
Date: 2016-04-20T13:40:13Z
From: Sidoti, Salvatore A.
Subject: 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