I have a df with below columns:
first_Date Profit Quantity Discount Segment
2012-01-01 23 24 45 seg1
2019-01-01 45 33 99 seg2 and so on
I perform groupby on first date column and find sum of profits, sum of quanitites, sum of discounts and most frequenct value of segment. Code made so far:
group2<-df %>%
mutate(date = as.Date(first_date),
year_mon = format(first_date, "%Y-%m")) %>%
group_by(first_date) %>%
summarise(sum_profit = sum(Profit),
sum_quantity = sum(Quantity),
sum_discount = sum(Discount),
)
Last column segment has not been captured here. I want to include the most frequent value of segment corresponding to each date above. How to do that