我有excel数据集如下:
Weight Quantity Price
72 5 460
73 8 720
75 20 830
95 2 490
91 15 680
82 14 340
88 30 250
89 6 770
78 27 820
98 24 940
99 29 825
Run Code Online (Sandbox Code Playgroud)
我想得到一个权重与数量数据透视表,每个类别的价格总和如下:
0-10 10-20 20-30
70-80 1180 830 820
80-90 770 340 250
90-100 490 680 1765
Run Code Online (Sandbox Code Playgroud)
我为各个类别创建了两个表,以使用dplyr
包获得平均值和计数,如下所示:
table1 <- group_by(dataset, Weight = cut(Weight, breaks = c(70,80,90,100))
result1 <- summarise(table1, Count = n(), Avg_Price = mean(Price, na.rm = T))
table2 <- group_by(dataset, …
Run Code Online (Sandbox Code Playgroud)