Let's say we have this data:
type <- paste("type", c(1,1,1,2,3,1,2,2,3,3,3,3,1,1))
dates <- seq(as.Date("2000/1/1"), by = "days", length.out = length(type))
mydataframe <- data.frame(type, dates)
I saw in other posts that rle
might do the job but I want to obtain a dataframe where for each type, I have the mean persistance in days. Something like:
> print(persistance)
type1 type2 type3
1 2 1.5 2.5
Anyone knows how to do this please? Thanks!