如何获得具有不同长度的列表中项目的频率

编程入门 行业动态 更新时间:2024-10-06 04:07:42
本文介绍了如何获得具有不同长度的列表中项目的频率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

假设我有以下列表:

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 ##

更多推荐

如何获得具有不同长度的列表中项目的频率

本文发布于:2023-11-29 15:35:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1646811.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何获得   长度   频率   项目   列表中

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!