Micheal
Micheal

Reputation: 15

Subset of the same column

I have a data frame and I need to do a subset of different group of different columns so I use this script

a <- subset(table, Response=="oxygen" & Operation=="blue" & Group=="A")

My question is: I need to include in this subgroup also the rows of the group B ( I have in the data frame also other type of group (C, D, F). I have tried to use this script but it doesn't work

a <- subset(table, Response=="oxygen" & Operation=="blue" & Group==c("A", "B"))

Could you tell me the correct syntax to use please?

Upvotes: 1

Views: 90

Answers (1)

Jaap
Jaap

Reputation: 83265

If you want to select both groups A & B, you need to use %in% instead of ==:

a <- subset(table, Response=="oxygen" & Operation=="blue" & Group %in% c("A", "B"))

Upvotes: 3

Related Questions