r - 检查 R 列中是否存在值向量,然后返回单个 True 值
问题描述
如果我有这个数据框:
df <- tibble(code = c("ABC", "DEF", "GHI"))
我有以下价值观:
my_values <- c("ABC","GHI")
如何检查我的对象 my_values 是否在数据框 df 中找到并返回单个 TRUE 布尔值?
我不在乎这些值出现了多少次,如果 my_values 中的任何或所有值出现在名为 code 的数据框列中,我只想返回一个奇异的 TRUE 布尔值?
My desired result is the single boolean TRUE - i'm stuck on this and have been using the %in% operator but to no avail.
解决方案
怎么样
any(df$code %in% my_values)
也许
any(my_values %in% df$code)
推荐阅读
- angular - 如何根据角度10中的条件设置选择
- javascript - 如果单击/选择子选项,则在鼠标移出时保持子菜单打开
- android - AVD Pixel_3a_API_28 的模拟器进程被杀死
- javascript - 弹出选项卡的第二个选项中的内容不显示任何内容
- python - 为什么我的冒泡排序不能正常工作?
- reactjs - 调度清除我所有的数据表单输入reactjs
- python-3.x - Python:sqlalchemy - 仅映射结果
- html - 如果我点击标题中的关于按钮,如何直接进入我网站的关于部分?
- python - 在 matplotlib 中绘制三角函数的周期
- php - 404 未找到:带有参数的 laravel api