识别重复并标记第一次发生和所有其他 [英] Identify duplicates and mark first occurrence and all others
问题描述
例如:
m <矩阵(c(1,2,1,3,1,4,1,2,2,3,2,3,1,2,5 ),ncol = 3)
m
duplicateated(m [,1])$ b $ b
输出:
[,1] [,2] [,3]
[1,] 1 4 2
[2,] 2 1 3
[3,] 1 2 1
[4,] 3 2 2
[5,] 1 3 5
[1] FALSE FALSE TRUE FALSE TRUE
但是,我不想要输出。我想要:
[1] TRUE FALSE TRUE FALSE TRUE
因为行[1,1]的值在m列1中显示3次。
当我看到这个问题时,我问自己Jim Holtman或Bill Dunlap对Rhelp的建议是什么?没有看档案,但我认为他们可能建议使用两个并行应用程序重复的
,其中一个默认值,一个与fromLast参数,并结合一个向量OR运算符。
duplicateated(m [,1])|重复(m [,1],fromLast = TRUE)
[1] TRUE FALSE TRUE FALSE TRUE
I'm trying to identify all rows which are represented twice or more in a matrix.
For example:
m <- matrix(c(1,2,1,3,1,4,1,2,2,3,2,3,1,2,5), ncol = 3)
m
duplicated(m[,1])
Outputs:
[,1] [,2] [,3]
[1,] 1 4 2
[2,] 2 1 3
[3,] 1 2 1
[4,] 3 2 2
[5,] 1 3 5
[1] FALSE FALSE TRUE FALSE TRUE
However, I do not want that output. I want:
[1] TRUE FALSE TRUE FALSE TRUE
since row[1,1]'s value appears 3 times in m's column 1.
When I saw this question I asked myself "what would Jim Holtman or Bill Dunlap advise on Rhelp?". Haven't looked in the archives, but I think they might have advised using two "parallel" applications of duplicated
, one with the defaults and one with the fromLast parameter and conjoining with a vector OR operator.
duplicated(m[,1]) | duplicated(m[,1], fromLast=TRUE)
[1] TRUE FALSE TRUE FALSE TRUE
这篇关于识别重复并标记第一次发生和所有其他的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!