I have looked at this question but it seems to me it addresses a different issue: Find a numeric pattern R
I have a large data set with multiple observations per id. Observation length (in m example below t) can vary across ids. I want to find patterns as defined by a subject making the same type of decision (below as type) at least three times in a row. My data looks like so:
id <- rep(1:3, each = 5)
t <- rep(1:5, 3)
type <- c("familiar", "familiar", "new", "completely new", "new", "new", "new", "new","new","new","new", "familiar", "completely new", "familiar", "new")
n <- data.frame( id, t, type )
n
How can I find patterns and indicate in a new column how many times they have made the decision to choose a certain type at least three times in a row?
(edit:) My desired output would be a value indicating the type a certain type was chosen at least three times in a row, e.g. something along the lines of "familiar_3+" or "new_3+".
Any help is much appreciated.