当前位置:网站首页>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边栏推荐
- How to troubleshoot SharePoint online map network drive failure?
- Lm08 mesh series mesh inversion (fine)
- [getting started] intercepting strings
- 0 basic introduction to single chip microcomputer: how to use digital multimeter and precautions
- getInputStream() has already been called for this request
- Transaction method call @transactional
- 手工挖XSS漏洞
- golang中的正则表达式使用注意事项与技巧
- Uni hot update
- Practice and Thinking on the architecture of a set of 100000 TPS im integrated message system
猜你喜欢

The Windows C disk is full

CPU设计实战-第四章实践任务一简单CPU参考设计调试

Microsoft stream - how to modify video subtitles

On several key issues of digital transformation

使用 setoolkit 伪造站点窃取用户信息

OJ input and output exercise

Lm08 mesh series mesh inversion (fine)

軟鍵盤高度報錯

Conception et mise en service du processeur - chapitre 4 tâches pratiques

Five combination boxing, solving six difficult problems on campus and escorting the construction of educational informatization
随机推荐
Provincial election + noi part I dynamic planning DP
Find the nearest n-th power of 2
On several key issues of digital transformation
CPU design practice - Chapter 4 practical tasks - simple CPU reference design and debugging
P4 installation bmv2 detailed tutorial
slice扩容机制分析
Aardio - Method of self constructed geticonhandle
How to troubleshoot SharePoint online map network drive failure?
Microsoft stream - how to modify video subtitles
Lm08 mesh series mesh inversion (fine)
Deep learning systematic learning
XX攻击——反射型 XSS 攻击劫持用户浏览器
Teach you how to apply for domestic trademark online step by step
5大组合拳,解决校园6大难题,护航教育信息化建设
Office365 - how to use stream app to watch offline files at any time
getInputStream() has already been called for this request
OJ输入输出练习
Scala language learning-07-constructor
[getting started] input n integers and output the smallest K of them
uni 热更新