2010-11-25 4 views

Répondre

12

il doit y avoir beaucoup plus simple ... mais comme oneliner:

d[(1+(s<-c(0,cumsum(1-(diff(d$DAYS)==1)))))%in%which(table(s)>=3),] 

étape par étape

d1 <- c(FALSE, diff(d$DAYS)!=1) 
d2 <- cumsum(d1)+1 
d3 <- table(d2) 
d4 <- which(d3 >= 3) 
d[d2 %in% d4,] 
+0

+1 solution soignée –

0

Une boucle for simple, fera ainsi:

d <- as.integer(DATA$DAYS) 
consec <- rep.int(FALSE, length(d)) 

for(i in 1:(length(d)-2)) 
    if(identical(d[i] + 1:2, d[i + 1:2])){ 
     consec[i + 0:2] <- TRUE 
    } 

DATA[consec, ] 
Questions connexes