Guest User

Untitled

a guest
May 24th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. Demo1 <- c(8,9,10,11)
  2. Demo2 <- c(13,14,15,16)
  3. Condition <- c('A', 'A', 'B', 'B')
  4. Var1 <- c(13,76,105,64)
  5. Var2 <- c(12,101,23,23)
  6. Var3 <- c(5,5,5,5)
  7.  
  8. df <- as.data.frame(cbind(Demo1, Demo2, Condition, Var1, Var2, Var3), stringsAsFactors = F)
  9. df[4:6] <- lapply(df[4:6], as.numeric)
  10.  
  11. df <- df %>%
  12. filter(Var1 > 100 | Var2 > 100 | Var3 > 100)
  13.  
  14. df %>%
  15. filter_at(vars(matches("^Var")), any_vars(.> 100))
  16. # Demo1 Demo2 Condition Var1 Var2 Var3
  17. #1 9 14 A 76 101 5
  18. #2 10 15 B 105 23 5
  19.  
  20. df[Reduce(`|`, lapply(df[grepl("^Var", names(df))], `>`, 100)),]
  21.  
  22. df[rowSums((df[,grepl("^Var",names(df))] > 100)) >= 1, ]
  23.  
  24. # Demo1 Demo2 Condition Var1 Var2 Var3
  25. # 2 9 14 A 76 101 5
  26. # 3 10 15 B 105 23 5
Add Comment
Please, Sign In to add comment