I am trying to construct a boolean for the following question:
For a given group did cond change values more than X times? Here is some sample data:
df <- rbind(
data.frame(
cond = c("cond1", "cond2", "cond1", "cond2", "cond3"),
day = 1:5,
group = "group1"
),
data.frame(
cond = c("cond1", "cond1", "cond1", "cond1", "cond2"),
day = 1:5,
group = "group2"
)
)
df
#> cond day group
#> 1 cond1 1 group1
#> 2 cond2 2 group1
#> 3 cond1 3 group1
#> 4 cond2 4 group1
#> 5 cond3 5 group1
#> 6 cond1 1 group2
#> 7 cond1 2 group2
#> 8 cond1 3 group2
#> 9 cond1 4 group2
#> 10 cond2 5 group2
The ordering is relevant here hence the day variable. But I am just trying to figure out how to detect when cond changes alot and then return those rows. Ideally will be fitting this into a group_by then filter idiom but really I'm not sure how to construct the boolean.