Guest User

Untitled

a guest
Aug 20th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. # generate some example data
  2. set.seed(1234)
  3. df <- data.frame(
  4. col1 = rbinom(100, 1, 0.5),
  5. col2 = rbinom(100, 1, 0.5),
  6. col3 = rbinom(100, 1, 0.5),
  7. col4 = rbinom(100, 1, 0.5),
  8. col5 = rbinom(100, 1, 0.5),
  9. col6 = rbinom(100, 1, 0.5))
  10.  
  11. # the long, explicit way with base R
  12. df[df$col2 == 1 & df$col4 == 1 & df$col6 == 1, ]
  13.  
  14. # or, equivalently with "subset"
  15. subset(df, col2 ==1 & col4 == 1 & df$col6 == 1)
Add Comment
Please, Sign In to add comment