Guest User

Untitled

a guest
Jul 17th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. df <- data.frame(foo = runif(10), bar = runif(10), boo = runif(10))
  2.  
  3. # bar boo foo
  4. # 1 0.9561519 0.2152603 0.90986454
  5. # 2 0.9971676 0.8101082 0.78158207
  6. # 3 0.6211555 0.9281131 0.59828786
  7. # 4 0.2332080 0.6063427 0.88131253
  8. # 5 0.6572534 0.3698642 0.61227246
  9. # 6 0.6940809 0.1464231 0.30366349
  10. # 7 0.3924425 0.3706134 0.05930352
  11. # 8 0.7918689 0.8808447 0.90571744
  12. # 9 0.2553619 0.9632559 0.52549238
  13. # 10 0.3772701 0.7657140 0.05102249
  14.  
  15. df %>%
  16. select(intersect(starts_with("b"), ends_with("oo")))
  17.  
  18. # boo
  19. # 1 0.2152603
  20. # 2 0.8101082
  21. # 3 0.9281131
  22. # 4 0.6063427
  23. # 5 0.3698642
  24. # 6 0.1464231
  25. # 7 0.3706134
  26. # 8 0.8808447
  27. # 9 0.9632559
  28. # 10 0.7657140
  29.  
  30. df %>%
  31. select(-ends_with("oo"))
  32. # bar
  33. # 1 0.9561519
  34. # 2 0.9971676
  35. # 3 0.6211555
  36. # 4 0.2332080
  37. # 5 0.6572534
  38. # 6 0.6940809
  39. # 7 0.3924425
  40. # 8 0.7918689
  41. # 9 0.2553619
  42. # 10 0.3772701
  43.  
  44. df %>%
  45. select(intersect(starts_with("b"), -ends_with("oo")))
  46.  
  47. # data frame with 0 columns and 10 rows
Add Comment
Please, Sign In to add comment