如果我有这个数据框:
df <- tibble(code = c("ABC", "DEF", "GHI"))
我有以下值:
my_values <- c("ABC","GHI")
我如何检查我的对象 my_values 是否在数据框 df 中找到并返回单个 TRUE bool 值?
我不关心这些值出现了多少次,如果 my_values 中的任何或所有值出现在名为 code 的数据框列中,我只想返回一个单一的 TRUE bool 值?
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)
关于r - 检查 R 列中是否存在值向量,然后返回单个 True 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67271305/