Okay, I have the following data frame with thousands of rows, Output of the dataframe is given below. This data frame records the orders on an e-commerce website, It lists the products purchased for each order id
| order_id| product_id|product_name |
|--------:|----------:|:--------------------------------|
| 1187899| 196|Soda |
| 1187899| 25133|Organic String Cheese |
| 1187899| 38928|0% Greek Strained Yogurt |
| 1187899| 26405|XL Pick-A-Size Paper Towel Rolls |
| 1187899| 39657|Milk Chocolate Almonds |
| 1187899| 10258|Pistachios |
| 1187899| 13032|Cinnamon Toast Crunch |
| 1187899| 26088|Aged White Cheddar Popcorn |
| 1187899| 27845|Organic Whole Milk |
| 1187899| 49235|Organic Half & Half |
| 1187899| 46149|Zero Calorie Cola |
| 1492625| 22963|Organic Roasted Turkey Breast |
| 1492625| 7963|Gluten Free Whole Grain Bread |
| 1492625| 16589|Plantain Chips |
| 1492625| 32792|Chipotle Beef & Pork Realstick |
The code used to list above data frame is:
temp <- orders %>%
inner_join(opt,by="order_id") %>%
inner_join(products,by="product_id") %>%
select(order_id,product_id,product_name)
kable(head(temp,15))
I want to count the most ordered products, basically, my output should be something like this:
product_id | Order_Count
196 10025
7963 9025
25133 8903
I cannot fig out how to go about this, I've tried following:
mutate(prods = count(product_id))
But it did not work i got a error saying: Error in mutate_impl(.data, dots) :
Evaluation error: no applicable method for 'groups' applied to an object of class "factor".
Any help will be appreciated!