-1

I have a data.frame with 2 columns and it looks like this

C1 C2
 A  1
 B  2
 A  3
 A  1
 C  4
 A  2
 C  1  

Now, I have form a table which contains the quantity of the items

Such as,

item   Quantity
   A          7
   B          2
   C          5

Please help with this!

thelatemail
  • 91,185
  • 12
  • 128
  • 188
Sandesh
  • 31
  • 5

1 Answers1

0

I think you just need aggregate

aggregate(df$c2, list(df$c1), sum)

#  Group.1 x
#1       A 7
#2       B 2
#3       C 5

Or as the @thelatemail suggested to preserve the column names you can use

aggregate(c2 ~ c1, data=df, sum)

#c1 c2
#1  A  7
#2  B  2
#3  C  5
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213