当前位置:网站首页>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边栏推荐
- Source code analysis of open source API gateway APIs IX
- 【批处理DOS-CMD-汇总】扩展变量-延迟变量cmd /v:on、cmd /v:off、setlocal enabledelayedexpansion、DisableDelayedExpansion
- Access报表实现小计功能
- Erreur de hauteur du clavier souple
- 防“活化”照片蒙混过关,数据宝“活体检测+人脸识别”让刷脸更安全
- window c盘满了
- golang中的正则表达式使用注意事项与技巧
- EDA open source simulation tool verilator beginner 6: debugging examples
- Lm08 mesh series mesh inversion (fine)
- String coordinates of number to excel
猜你喜欢

Set up file server Minio for quick use

Airsim雷达相机融合生成彩色点云

Teach you how to apply for domestic trademark online step by step
![[untitled]](/img/d9/5e97f2de256b9749131b5bf1437d24.png)
[untitled]

Use threejs simple Web3D effect

How to use layui to display the data in the database in the form of tables
![[question brushing] character statistics [0]](/img/cc/f5aaecd920c502180303d92447e54f.png)
[question brushing] character statistics [0]

web254

Embedded-c language-10-enumeration / (function) pointer (function) / multi-level pointer /malloc dynamic allocation / file operation

Differential: definition of total differential, partial derivative, gradient
随机推荐
PostgreSQL source code learning (26) -- windows vscode remote debugging PostgreSQL on Linux
Provincial election + noi part I dynamic planning DP
Precautions and skills in using regular expressions in golang
[redis] it takes you through redis installation and connection at one go
Book of quantitative trading - reading notes of the man who conquers the market
[getting started] enter the integer array and sorting ID, and sort its elements in ascending or descending order
OJ input and output exercise
When using charts to display data, the time field in the database is repeated. How to display the value at this time?
凸印的印刷原理及工艺介绍
Scala语言学习-07-构造器
Android screen adaptation (using constraintlayout), kotlin array sorting
Chinese font Gan: zi2zi
Teach you how to apply for domestic trademark online step by step
软键盘高度报错
【刷题】字符统计【0】
Insufficient executors to build thread pool
源代码加密的意义和措施
[getting started] intercepting strings
XX attack - reflective XSS attack hijacking user browser
php laravel微信支付