简体   繁体   English

如何对 r 中的多个分类列值进行子集化?

[英]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.我正在研究一个大型加权国家数据集,其中包括受访者的 state 作为变量。 I wanted to create subsets with multiple states (ie AZ, IL, NJ).我想创建具有多个州(即 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.我可以在 Excel 中删除不需要的 state 响应,但如果在 R 中有一种方法可以做到这一点,那就太好了。

You are looking for STATE %in% c('AZ', 'IL', 'NJ') .您正在寻找STATE %in% c('AZ', 'IL', 'NJ')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM