保留仅出现一次的向量元素或矩阵列
我有一个矩阵:
A<-t(matrix(
c(0, 0, 1,
0, 0, 0,
0, 0, 1,
0, 0, 1,
0, 0, 0,
1, 1, 0), 3, 6))
我需要保留仅出现一次的列。因此,预期的结果只是第三列:(1,0,1,1,0,0,0)。
I have a matrix:
A<-t(matrix(
c(0, 0, 1,
0, 0, 0,
0, 0, 1,
0, 0, 1,
0, 0, 0,
1, 1, 0), 3, 6))
and I need to keep columns that appear only once. So, the expected result is just the 3rd column: (1, 0, 1, 1, 0, 0).
I have found the unique and duplicated functions but I need something stronger to delete all columns that appear more than once (in my example the 1st and 2nd).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
看来我们需要双重
重复
。这个想法也适用于向量。
Looks like we need a double
duplicated
.The idea applies to a vector, too.
我们可以使用
汇总
在下面尝试基本R代码,以汇总a
的唯一信息,或
等效
We can try the base R code below using
aggregate
to summarize the uniqueness info ofA
by columnsor equivalently
which gives
另一个可能的解决方案:
或:
Another possible solution:
Or: