检查列表以找出R中的所有值都相同(Check List to find out all values are same in R)
我的清单如下
l = list(c("a", "b", "c"), c("a", "b", "c"), c("a", "b", "c"))我想使用apply family函数检查它们中的每一个是否包含相同的值。
我想要下面的答案
TRUE, TRUE, TRUEI have list as follows
l = list(c("a", "b", "c"), c("a", "b", "c"), c("a", "b", "c"))I want to check that each of them contain same values using apply family functions.
I want following answer
TRUE, TRUE, TRUE最满意答案
我们可以使用duplicated
duplicated(l)|duplicated(l, fromLast=TRUE) #[1] TRUE TRUE TRUE如果我们需要比较list元素的所有组合, combn是另一种方式
combn(seq_along(l), 2, FUN= function(x) all(l[[x[1]]] == l[[x[2]]])) #[1] TRUE TRUE TRUEWe can use duplicated
duplicated(l)|duplicated(l, fromLast=TRUE) #[1] TRUE TRUE TRUEIf we need to compare all the combinations of list elements, combn is another way
combn(seq_along(l), 2, FUN= function(x) all(l[[x[1]]] == l[[x[2]]])) #[1] TRUE TRUE TRUE更多推荐
发布评论