R 列表中向量的频率

R 列表中向量的频率,r,list,count,R,List,Count,假设我有一张清单 test <- list(c(1, 2, 3), c(2, 4, 6), c(1, 5, 10), c(1, 2, 3), c(1, 5, 10), c(1, 2, 3)) 在R中有什么简单的方法可以实现这一点吗?您可以粘贴并使用表格,即 as.data.frame(table(sapply(test, paste, collapse = ' '))) 这就给了, 函数unique()可以用于列表。计数时可以使用相同的(): 测试 as.data.frame(tabl

假设我有一张清单

test <- list(c(1, 2, 3), c(2, 4, 6), c(1, 5, 10), c(1, 2, 3), c(1, 5, 10), c(1, 2, 3))

在R中有什么简单的方法可以实现这一点吗?

您可以粘贴并使用
表格,即

as.data.frame(table(sapply(test, paste, collapse = ' ')))
这就给了,

函数
unique()
可以用于列表。计数时可以使用相同的(
):

测试
as.data.frame(table(sapply(test, paste, collapse = ' ')))
    Var1 Freq
1  1 2 3    3
2 1 5 10    2
3  2 4 6    1
test <- list(c(1, 2, 3), c(2, 4, 6), c(1, 5, 10), c(1, 2, 3), c(1, 5, 10), c(1, 2, 3))
Lcount <- function(xx, L) sum(sapply(L, identical, y=xx))
sapply(unique(test), FUN=Lcount, L=test)
unique(test)
result <- data.frame(
 Set=sapply(unique(test), FUN=paste0, collapse=','),
 count= sapply(unique(test), FUN=Lcount, L=test)
)
result
# > result
#      Set count
# 1  1,2,3     3
# 2  2,4,6     1
# 3 1,5,10     2