Guest User

Untitled

a guest
Oct 23rd, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.35 KB | None | 0 0
  1. dum == 1
  2. times - lead(times) < 30
  3.  
  4. mdf <- data.frame(id= c(1,2,2,2,3,3,3,4,4), dum= c(1,0,1,0,0,0,1,1,0), times= c(10,20,20,45,60,70,80,120,170))
  5.  
  6. id dum times
  7. 2 1 20
  8.  
  9. library(dplyr)
  10.  
  11. mdf1 <- group_by(mdf, id )
  12. %>%
  13. filter(dum == 1 , times - lead(times) < 30)
  14.  
  15. id dum times
  16. (dbl) (dbl) (dbl)
  17. 1 2 1 20
  18. 2 4 1 120
Add Comment
Please, Sign In to add comment