简体   繁体   English

如何创建 Excel Pivot 表到 R

[英]How to Create Excel Pivot Table to R

I want to create a pivot table from my data set in excel to R.我想从我在 excel 到 R 的数据集中创建一个 pivot 表。 I have been following this tutorial on how to do this: http://excel2r.com/pivot-tables-in-r-basic-pivot-table-columns-and-metrics/ .我一直在关注如何执行此操作的本教程: http://excel2r.com/pivot-tables-in-r-basic-pivot-table-columns-and-metrics/ I have used the codes mentioned in this tutorial by replacing it with my own data variables, but I keep getting an error message noting: Error: select() doesn't handle lists.我已使用本教程中提到的代码,将其替换为我自己的数据变量,但我不断收到一条错误消息,指出:错误: select()不处理列表。

What does this error message mean and how I can I fix this?此错误消息是什么意思,我该如何解决?

The R-Script I have been using from the tutorial is:我在本教程中使用的 R-Script 是:

library(dplyr) library(tidyr)图书馆(dplyr) 图书馆(tidyr)

pivot <- df %>%
        select(Product.Category, Region, Customer.Segment, Sales)%>%
        group_by(Product.Category, Region, Customer.Segment) %>%
        summarise(TotalSales = sum(Sales))

Thank you in advance for the help!提前感谢您的帮助!

By your error message: "select() doesn't handle lists.", I supose that your object called df isn't a dataframe.根据您的错误消息:“select() 不处理列表。”,我假设您的 object 称为df不是 dataframe。

Maybe you have a dataframe inside a list.也许您在列表中有一个 dataframe 。

Try this in your R console:在您的 R 控制台中试试这个:

class(df)

If the class is a list, you need take off the dataframe from the list.如果 class 是列表,则需要从列表中删除 dataframe。 You can do this by the position.您可以通过 position 执行此操作。 Probably in the first position.大概在第一个position。 df[[1]]

The functions that you are using, works only for dataframes in general.您正在使用的函数通常仅适用于数据帧。 (And tibbles, that is a another type of dataframe) (还有 tibbles,这是另一种类型的数据框)

Like this example:像这个例子:

在此处输入图像描述

I hope it works for you.我希望这个对你有用。

And, for the next time, try to make an reproducible example.并且,下一次,试着做一个可重复的例子。 You could at least print your dataframe original, before try to use these functions, that way I could help you efficiently.在尝试使用这些功能之前,您至少可以打印您的 dataframe 原件,这样我可以有效地帮助您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM