0

I know how to use multiple &'s or multiple |'s at the same time. Is it possible to use both at the same time? Basically, I would like to combine the below codes, using the or command, into one line. Then I wouldn't have to merge D and D2 to get my final output.

D <- subset(data, Quits1/Emp1 >= .5 & size == 1, )

D2 <- subset(data, Emp1 - Emp2 >= 100 & size == 1, )
Csislander
  • 2,100
  • 1
  • 13
  • 16

1 Answers1

4

I have literally never used R in my life, so if I'm horribly wrong about this I'm sorry!

But I don't see any reason why this wouldn't work:

D <- subset(data, (Quits1/Emp1 >= .5 | Emp1 - Emp2 >= 100) & size == 1, )

However, as @shadow has pointed out, use of subset is discouraged. So here's my attempt at using the proper method:

D <- data[ (data$Quits1 / data$Emp1 >= .5 | data$Emp1 - data$Emp2 >= 100) & data$size == 1,]
Community
  • 1
  • 1
Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592