Skip to content
Prev 301048 / 398503 Next

Collapsing a vector/data-frame based on the previous values

Here is another way of doing it:
+ "27/07/2012", "28/07/2012", "24/07/2012", "25/07/2012", "26/07/2012",
+ "27/07/2012", "28/07/2012"), State = c(1L, 1L, 1L, 1L, 1L, -1L,
+ -1L, -1L, 1L, -1L)), .Names = c("Date", "State"), class = "data.frame",
+ row.names = c(NA,
+ -10L))
Date State diff
1  24/07/2012     1 TRUE
6  24/07/2012    -1 TRUE
9  27/07/2012     1 TRUE
10 28/07/2012    -1 TRUE


On Tue, Jul 24, 2012 at 2:40 AM, Raghuraman Ramachandran
<optionsraghu at gmail.com> wrote: