0
Items = c('Pepsi','Cola','Water','Pepsi','Cola')
Quantities = c(2,1,3,1,1)
df = data.frame(Items,Quantities)

My dataframe is :

Items  Quantities
Pepsi     2
Cola      1
Water     3
Pepsi     1
Cola      1

I want to calculate frequency of these items. I tried to use count by count(df,"Items") but it return the count on items. What I want is count using quantities by each items.

My expected data frame:

Items    Freq  
Pepsi     3         
Cola      2
Water     3

Please let me know any ideas to that

Ronak Shah
  • 355,584
  • 18
  • 123
  • 178
Joe Ng
  • 35
  • 5

0 Answers0