如何在R中汇总此数据

编程入门 行业动态 更新时间:2024-10-24 22:27:24
本文介绍了如何在R中汇总此数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在R中有一个具有以下结构的数据框。

I have a data frame in R with the following structure.

> testData date exch.code comm.code oi 1 1997-12-30 CBT 1 468710 2 1997-12-23 CBT 1 457165 3 1997-12-19 CBT 1 461520 4 1997-12-16 CBT 1 444190 5 1997-12-09 CBT 1 446190 6 1997-12-02 CBT 1 443085 .... 77827 2004-10-26 NYME 967 10038 77828 2004-10-19 NYME 967 9910 77829 2004-10-12 NYME 967 10195 77830 2004-09-28 NYME 967 9970 77831 2004-08-31 NYME 967 9155 77832 2004-08-24 NYME 967 8655

我想做的是生成一张表格,显示指定日期的商品,商品在每个交换代码中的总oi。因此,这些行将由

What I want to do is produce a table the shows for a given date and commodity the total oi across every exchange code. So, the rows would be made up of

unique(testData$date)

,列将是

unique(testData$comm.code)

每个单元格将是给定所有exch.code上的oi总数

and each cell would be the total oi over all exch.codes on a given day.

谢谢

推荐答案

plyr 软件包很擅长此操作,您应该使用单个 ddply( )调用。像(未测试)

The plyr package is good at this, and you should get this done with a single ddply() call. Something like (untested)

ddply(testData, .(date,comm.code), function(x) sum(x$oi))

应该可以。

更多推荐

如何在R中汇总此数据

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

发布评论

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

>www.elefans.com

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