本文介绍了如何获得具有不同长度的列表中项目的频率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有以下列表:
test<-list(c("a","b","c"),c("a"),c("c")) >test [[1]] [1] "a" "b" "c" [[2]] [1] "a" [[3]] [1] "c"我该怎么做(或要使用的功能)来获得像这样的列表中唯一项目的出现频率??
What do I do(or functions to use) to get the frequency of unique items in a list like this:?
a 2 b 1 c 2我尝试使用table(test),但出现以下错误
I tried using table(test), but I get the following error
> table(test) Error in table(test) : all arguments must have the same length推荐答案
test <- list(c("a", "b", "c"), c("a"), c("c")) # If you want count accross all elements table(unlist(test)) ## ## a b c ## 2 1 2 # If you want seperate counts in each item of list lapply(test, table) ## [[1]] ## ## a b c ## 1 1 1 ## ## [[2]] ## ## a ## 1 ## ## [[3]] ## ## c ## 1 ##
更多推荐
如何获得具有不同长度的列表中项目的频率
发布评论