Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- set.seed(500)
- dat <- data.frame(c1 = rnorm(10), c2 = sample(1:3, 10, TRUE),
- c3 = sample(LETTERS[1:5], 10, TRUE))
- # c1 c2 c3
- # 1 0.96848929 1 A
- # 2 1.96536781 3 A
- # 3 0.88632253 1 D
- # 4 0.03054026 2 A
- # 5 0.94955742 1 B
- # 6 -0.57673001 3 E
- # 7 0.72152335 3 E
- # 8 0.61909890 3 A
- # 9 0.02100582 1 E
- # 10 0.27485018 1 A
- dat[dat$c3 %in% dat[dat$c1 >= 0.9 & dat$c2 == 1, 'c3'], ]
- # c1 c2 c3
- # 1 0.96848929 1 A
- # 2 1.96536781 3 A
- # 4 0.03054026 2 A
- # 5 0.94955742 1 B
- # 8 0.61909890 3 A
- # 10 0.27485018 1 A
- library(dplyr)
- dat %>% filter(c3 %in% (dat %>% filter(c1 >= 0.9, c2 == 1) %>% .$c3))
- # c1 c2 c3
- # 1 0.96848929 1 A
- # 2 1.96536781 3 A
- # 3 0.03054026 2 A
- # 4 0.94955742 1 B
- # 5 0.61909890 3 A
- # 6 0.27485018 1 A
Advertisement
Add Comment
Please, Sign In to add comment