r - 寻找 R Studi 函数/代码来交叉引用变量
问题描述
如果有人能就如何建立两个变量之间的关系向我提供建议,我将不胜感激。这可能非常简单,但我是 R 新手。我无法附上我的数据集 (X2015_11_metropolitan_stop_and_search) 的照片,但这是我感兴趣的两个变量的 dput:
dput(X2015_11_metropolitan_stop_and_search$Object of search)
c("Offensive weapons", "Controlled drugs", "Controlled drugs", "Fireworks", "Controlled drugs", "Stolen goods", "Controlled drugs", "Controlled drugs", "Offensive weapons", "Controlled drugs", "Fireworks", "Controlled drugs", "Controlled drugs", "Evidence of offences under the Act", "Controlled drugs", "Controlled drugs", "Controlled drugs", "Controlled drugs", "Controlled drugs", "Controlled drugs", "Controlled drugs", "Controlled drugs", "Controlled drugs", "Controlled drugs", "Controlled drugs", "Controlled drugs", "Offensive weapons", "Stolen goods", "Controlled drugs", "Controlled drugs", "Offensive weapons", "Offensive weapons", "Controlled drugs", "Controlled drugs", "Controlled drugs", "Controlled drugs", "Controlled drugs" )
dput(X2015_11_metropolitan_stop_and_search$Outcome)
c("Suspect arrested", "Nothing found - no further action", "Suspect arrested",
"Nothing found - no further action", "Nothing found - no further action",
"Nothing found - no further action", "Offender given drugs possession warning",
"Nothing found - no further action", "Offender given drugs possession warning",
"Nothing found - no further action", "Nothing found - no further action",
"Suspect arrested", "Suspect arrested", "Offender given drugs possession warning",
"Suspect arrested", "Suspect arrested", "Nothing found - no further action",
"Nothing found - no further action", "Suspect arrested", "Nothing found - no further action",
"Nothing found - no further action", "Suspect arrested", "Suspect arrested",
"Nothing found - no further action", "Nothing found - no further action",
"Nothing found - no further action", "Nothing found - no further action",
"Suspect arrested", "Nothing found - no further action", "Nothing found - no further action",
"Nothing found - no further action", "Nothing found - no further action",
"Nothing found - no further action", "Nothing found - no further action",
"Nothing found - no further action", "Nothing found - no further action",
"Suspect arrested", "Nothing found - no further action", "Nothing found - no further action",
"Suspect arrested", "Nothing found - no further action", "Nothing found - no further action",
"Nothing found - no further action", "Suspect arrested", "Suspect arrested",
"Nothing found - no further action", "Nothing found - no further action",
"Nothing found - no further action", "Offender given drugs possession warning",
"Suspect arrested", "Offender given penalty notice", "Nothing found - no further action")
变量“搜索对象”和“结果”有少量可能的值。我希望能够看到那些“结果”值为“嫌疑人被捕”的个别事件的“搜索对象”值。那可能吗?
如果我需要包含更多信息,请告诉我。
解决方案
您可以尝试以下方法:
X2015_11_metropolitan_stop_and_search$Object of search[X2015_11_metropolitan_stop_and_search$Outcome == "Suspect arrested"]
这将返回结果为“嫌疑人被捕”的“搜索对象”的所有值。一个通用版本是:
data$column1[data$column2 == "dataValue"]
另请查看 which() 函数以返回符合您在函数中指定的参数的数据的索引号。
推荐阅读
- inno-setup - 使用 Inno Setup 将 exe 文件注册为 OLE 服务器
- python - 全量化不排除 int8 数据将模型输入层更改为 int8
- javascript - TextArea 不会滚动到最大底部
- r - 如何为序列设置长度?
- java - 在 Filechooser 中获取字符串路径
- typescript - TypeORM - connectionNotFoundError
- java - Java获取包含至少一个文件的文件夹列表
- php - Shopify 允许将任意数量的单位添加到购物车
- r - 如何在循环内获取不同模型的摘要?
- apache-zookeeper - Mesos 从站是否需要与 Mesos 主站联系?