Skip to content
Prev 168756 / 398503 Next

Splitting a data frame with break points where factor changes value

Here is one approach.  You might want to change NAs to 0 if you want
them included in the split

set.seed(1)
x <- sample(c(1, -1), 30, TRUE)
x
# determine where changes occur
change <- cumsum(c(0, diff(x) != 0))
change
split(x, change)


On Sat, Jan 31, 2009 at 5:25 AM, Titus von der Malsburg
<malsburg at gmail.com> wrote: