Using incomparables argument within duplicated() i

2020-04-20 21:13发布

I have the following matrix:

structure(c(NA, NA, "2, 3, 5, 7", "1, 3, 5, 7", NA, "1, 3, 7", 
"2, 3, 5, 8", "2, 3, 5, 7", "1, 5, 7, 8", "1, 2, 3, 7, 8", "1, 2, 8", 
"2, 3, 5, 7", NA, "3, 5, 6, 7", "1, 3, 6, 7", "2, 3, 5, 8", "2, 3, 5, 7", 
NA, "1, 3, 7", "1, 4", "3, 4, 5, 7", NA, "3, 5, 7", NA, NA, NA, 
"1, 5, 7", "1, 2, 6, 7", NA, NA, "1, 2, 4, 5, 7", "2, 5, 6, 7", 
"1, 4, 6, 7", "2, 5, 8", "2, 5", "5, 8", "2, 6, 7", NA, NA, "2, 7", 
NA, "6, 7", NA, NA, NA, "1, 2", "1, 2, 4", "2, 4", "1, 2, 3, 4, 5", 
"2, 3, 5", NA, NA, NA, NA, "2, 3, 8", "2, 8", NA, NA, "2, 3, 7", 
NA, "3, 5", NA, "5, 7", NA, NA, "2, 3", "2, 3, 7", NA, NA, NA, 
"3, 7", NA, NA, NA, NA, "3, 4", NA, "3, 4", NA, NA, NA), .Dim = c(9L, 
9L))

I want to find which elements are duplicated ignoring the missing elements. I use the following code:

duplicated(cand, MARGIN = 0, incomparables = NA)

However, this returns the following error:

Error: argument 'incomparables != FALSE' is not used (yet)

Any thoughts?

标签: r
1条回答
家丑人穷心不美
2楼-- · 2020-04-20 21:37

The help page help(duplicated) says:

incomparables
a vector of values that cannot be compared. FALSE is a special value, meaning that all values can be compared, and may be the only value accepted for methods other than the default. It will be coerced internally to the same type as x.

So incomparables = NA seems to not work. However, you can get the effect that you are looking for with:

duplicated(cand, MARGIN = 0) & !is.na(cand)
查看更多
登录 后发表回答