计算 R 中因子的出现次数,报告的计数为零

您所在的位置:网站首页 房屋买卖流程图解 计算 R 中因子的出现次数,报告的计数为零

计算 R 中因子的出现次数,报告的计数为零

2023-01-02 16:46| 来源: 网络整理| 查看: 265

本文介绍了计算 R 中因子的出现次数,报告的计数为零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想计算一个因子在数据框中出现的次数.例如,要计算下面代码中给定类型的事件数:

I want to count the number of occurrences of a factor in a data frame. For example, to count the number of events of a given type in the code below:

library(plyr) events

简单地在因子上调用 table() 已经做了正确的事情,ddply() 也可以如果你告诉它不要drop:

Simply calling table() on the factor already does the right thing, and ddply() can too if you tell it not to drop:

R> ddply(events, .(type), summarise, quantity = sum(quantity), .drop=FALSE) type quantity 1 A 3 2 B 1 3 C 0 R>

这篇关于计算 R 中因子的出现次数,报告的计数为零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3