I am trying to build a pivot table using R for my excel dataset. I need to group the numbers(which are in a column called, weights ranging from 70-100. There is a price associated with each of these weights. I need to find the mean(weights), max(weights), min(weights) and the count of products in each weight category. There are about 3000 obs. of 25 variables. Weights and Price are two of them. Snippet of the data:
Weight Price Order No. Date_Ordered Invoiced_Date Region
85 $2300
78 $5600
100 $3490
95 $2450
90 $5890
I am looking for something like:
Weight Count Mean(Price) Min(Price) Max(Price)
70-75(including 75)
75-80
80-85
85-90
90-95
95-100
I am able to get the count but I am not able to get the mean, min and max for each weight category:
#Import the dataset
dataset = read.xlsx('Product_Data.xlsx')
gdataset <- group_by(dataset, Weight)
attach(gdataset)
periods <- seq(from = 70, to = 100, by 5)
snip < -cut(Weight, breaks = periods, right = TRUE, include.lowest = TRUE)
report <- cbind(table(snip))