条件计数和分组在R

编程入门 行业动态 更新时间:2024-10-28 00:19:53
本文介绍了条件计数和分组在R的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如果符合条件 x == 0 ,我想计算类型 。

I would like to count how many rows there are per type if they meet the condition x == 0. Sort of like a group by in SQL

以下是数据示例

type x search 0 NULL 0 public 0 search 1 home 0 home 1 search 0

推荐答案

我假设你想要找到行数

如果是这种情况,那么我想你有x作为一个变量表示在一个特定的条件柱。 x可以有多个值。假设你想在x为0时找到你的数据中有多少行。这可以通过:

If this is the case, then I suppose you have "x" as a variable represented in a column. "x" can take multiple values. Suppose you want to find how many rows are there in your data when x is 0. This could be done by:

nrow(subset(data, x=="0")

'data'是数据集的对象名称在R中

'data' is the object name for your dataset in R

编辑:

我现在看到您编辑的数据框可以使用这个来解决你的问题:

I am seeing your edited dataframe now. You could use this to solve your problem:

table(data$type, data$x)

更多推荐

条件计数和分组在R

本文发布于:2023-11-22 08:41:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1616732.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:条件

发布评论

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

>www.elefans.com

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