在较小的字符向量列表中查找元素,但不在大列表中查找元素 [英] Find elements not in smaller character vector list but in big list

查看:43
本文介绍了在较小的字符向量列表中查找元素,但不在大列表中查找元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个大清单和小清单.我想知道大列表中的哪些元素不在小列表中.该列表由属性组成

I have the two big and small list. I want to know which of the elements in big list are not in smaller list. The list consists of property

([1] "character"           "vector"              "data.frameRowLabels"
[4] "SuperClassMethod"

这是一个小例子,我遇到了错误

Here is small example and error I am getting

 A <- c("A", "B", "C", "D")
 B <- c("A", "B", "C")
  new <- A[!B]
Error in !B : invalid argument type

预期的输出是新的<-c("D")

The expected output is new <- c("D")

推荐答案

查看help("%in%")-该页面底部始终有一个示例来解决这种情况.

Look at help("%in%") - there's an example all the way at the bottom of that page that addresses this situation.

A <- c("A", "B", "C", "D")
B <- c("A", "B", "C")
(new <- A[which(!A %in% B)])

# [1] "D"

正如泰勒所指出的,我应该听取自己的建议并阅读支持文档.在本例中使用%in%时,不需要which().所以,

As Tyler points out, I should take my own advice and read the support documents. which() is unnecessary when using %in% for this example. So,

(new <- A[!A %in% B])

# [1] "D"

这篇关于在较小的字符向量列表中查找元素,但不在大列表中查找元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆