I want to use behavioural data to calculate the number of items caught. This is my example data:
df <- data.frame(id = as.factor(c(51,51,51,51,51,51,51,52,52,52,52,52,52)),
type = c("(K)","(K)","(K)","(K)","","","","(K)","(K)","","(K)","","(K)"))
I would like to count each of my "K"'s based on if they are consecutive or not. If consecutive, the string should count as one. if there is a gap between, they should both count as one.. so final tally will be 2.
Hope that makes sense... for the example above, I would like my final output data to look like this
id type tally
1 51 (K) 1
2 52 (K) 3
I thought aggregate might do this, however it counts the total number in a column so for 51 tally=4 rather than 1
Any help would be appreciated
Thanks Grace