user3661400
user3661400

Reputation: 1

using both and & and or | at the same time in r?

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, )

Upvotes: 0

Views: 1079

Answers (1)

Niet the Dark Absol
Niet the Dark Absol

Reputation: 324650

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,]

Upvotes: 4

Related Questions