【发布时间】:2020-08-03 15:25:59
【问题描述】:
这是关于来自 R 的数据集 MplsStops。
我选择了我需要的数据集的两列:race 和 citationIssued。
在那之后,我省略了所有的 NA。
然后我想通过列比赛中的黑白值过滤所有 citationIssued 值。
我怎样才能做到这一点?
感谢您的帮助
【问题讨论】:
这是关于来自 R 的数据集 MplsStops。
我选择了我需要的数据集的两列:race 和 citationIssued。
在那之后,我省略了所有的 NA。
然后我想通过列比赛中的黑白值过滤所有 citationIssued 值。
我怎样才能做到这一点?
感谢您的帮助
【问题讨论】:
欢迎来到 Stack Overflow!
如果您想通过R 学习数据处理,dplyr 包是您的朋友。
这个怎么样:
library(carData) # get the sample data
library(dplyr) # load dplyr for data processing functions
MplsStops %>% # start with the data and pipe it to the next line
select(race, citationIssued) %>% # keep two variables and pipe to next line
filter(race %in% c("Black", "White") & !is.na(citationIssued))
如果回答,请点击绿色复选标记,如果没有,请添加评论以获得更多帮助。
【讨论】: