在R中创建与Excel数据透视表相同的数据透视表

时间:2019-03-26 19:58:52

标签: r excel pivot

我有两张纸的excel工作簿:

Sheet1 name = Test(source data)

Sheet2 name = Test_pivot(excel pivot table created from source data)

这是输入(不可触摸)。

我的要求是,Sheet1每天都用新记录进行更新。现在,我想用R编写代码,该代码将每天读取Sheet1并使用新接收的数据刷新Sheet2(excel透视表)。

如何通过R完成此操作?

1 个答案:

答案 0 :(得分:0)

在您的示例中,我看不到大量数据或任何数据。无论如何,这是一个如何在非连续mtcars数据集上运行数据透视的通用示例。

library(rpivotTable)
data(mtcars)
rpivotTable(mtcars,rows="gear", cols=c("cyl","carb"),width="100%", height="400px") 

enter image description here

有关如何在R中使用枢轴的其他想法,请参见下面的链接,包括对其进行制图和制图,以及如何基于Excel文件中包含的数据创建枢轴。

https://cran.r-project.org/web/packages/rpivotTable/vignettes/rpivotTableIntroduction.html

http://excel2r.com/pivot-tables-in-r-basic-pivot-table-columns-and-metrics/

相关问题