当前位置:网站首页>Count number of rows per group and add result to original data frame
Count number of rows per group and add result to original data frame
2022-07-01 08:14:00 【javail】
problem :
Say I have a data.frame object: Let's say I have one data.frame object :
df <- data.frame(name=c('black','black','black','red','red'), type=c('chair','chair','sofa','sofa','plate'), num=c(4,5,12,4,3))Now I want to count the number of rows (observations) of for each combination of name and type . Now I want to calculate name and type Rows per combination ( Observe ).This can be done like so: This can be done like this :
table(df[ , c("name","type")])or possibly also with plyr , (though I am not sure how). Or you can use plyr ,( Although I'm not sure how ).
However, how do I get the results incorporated into the original data frame? however , How to merge the results into the original data frame ?So that the results will look like this: The result will be as follows :
df# name type num count# 1 black chair 4 2# 2 black chair 5 2# 3 black sofa 12 1# 4 red sofa 4 1# 5 red plate 3 1where count now stores the results from the aggregation. Now? count Store aggregated results .
A solution with plyr could be interesting to learn as well, though I would like to see how this is done with base R. Use plyr Your solution can also be interesting , Although I want to see how this is used on the basis R Accomplished .
Solution :
Reference resources : https://stackoom.com/en/question/VGEy边栏推荐
- web254
- 【入门】提取不重复的整数
- Transaction method call @transactional
- 使用threejs简单Web3D效果
- SharePoint - modify web application authentication using PowerShell
- getInputStream() has already been called for this request
- 0 basic introduction to single chip microcomputer: how to use digital multimeter and precautions
- XX攻击——反射型 XSS 攻击劫持用户浏览器
- 【Redis】一气呵成,带你了解Redis安装与连接
- Rumtime 1200 upgrade: London upgrade support, pledge function update and more
猜你喜欢

Learn the knowledge you need to know about the communication protocol I2C bus

Practice and Thinking on the architecture of a set of 100000 TPS im integrated message system

Adding color blocks to Seaborn clustermap matrix

Lm08 mesh series mesh inversion (fine)

Set up file server Minio for quick use

使用beef劫持用戶瀏覽器

LM08丨网格系列之网格反转(精)

P4 installation bmv2 detailed tutorial

Use threejs simple Web3D effect

seaborn clustermap矩阵添加颜色块
随机推荐
SharePoint - modify web application authentication using PowerShell
栈实现计算器
SQL number injection and character injection
【入门】提取不重复的整数
力扣每日一题-第31天-1790.仅执行一次字符串交换能否使两个字符串相等
sqlalchemy创建MySQL_Table
Keithley 2100 software 𞓜 Keithley2400 test software ns SourceMeter
shardingSphere
量化交易之读书篇 - 《征服市场的人》读书笔记
OJ input and output exercise
软键盘高度报错
Provincial election + noi Part VI skills and ideas
Connect timed out of database connection
Data analysis notes 11
slice扩容机制分析
Rumtime 1200 upgrade: London upgrade support, pledge function update and more
go通用动态重试机制解决方案的实现与封装
Adding color blocks to Seaborn clustermap matrix
Why are some Wills made by husband and wife invalid
[redis] it takes you through redis installation and connection at one go