Jennear
Jennear

Reputation: 13

How to subset multiple categorical column values in r?

I'm working on a large weighted national dataset that includes respondent's state as a variable. I wanted to create subsets with multiple states (i.e. AZ, IL, NJ). All of the threads I found show how to subset from multiple columns but is there a way to create subsets from multiple categorical values in the same column? One of my attempts is included below and all attempts result in either an error or subsets with only the Arizona respondents.

AZILNJ <- subset(FFE.PRAMS, STATE=='AZ', 'IL', 'NJ') 

I could just delete unwanted state responses in Excel, it'd be nice if there was a way to do this in R though.

Upvotes: 1

Views: 414

Answers (1)

WhatIf
WhatIf

Reputation: 636

You are looking for STATE %in% c('AZ', 'IL', 'NJ').

Upvotes: 2

Related Questions