-5

I have a dataframe like this:

count  date
1233 2012-10-12     
3232 2012-10-12     
2334 2012-10-12     
3330 2012-10-13    
1445 2012-10-13     
3455 2012-10-13     
7632 2012-10-13     

I'd like to know the sum of count of each day, is any simple way to do that? Also, how to select the data of certain date with certain logic?

Ziwei
  • 57
  • 1
  • 3
  • 11

3 Answers3

2

Let dat be your data frame, to get aggregation per day, you can use

aggregate(count ~ date, data = dat, FUN = sum)

To select data of a certain date, say "2012-10-12", you may do

subset(dat, date == "2012-10-12")
Zheyuan Li
  • 71,365
  • 17
  • 180
  • 248
1

Using the plyr package assuming your data is called df you can do:

ddply(df, "date", numcolwise(sum))

Warner
  • 1,353
  • 9
  • 23
1

Another base R option is xtabs

xtabs(count~date, dat)
akrun
  • 874,273
  • 37
  • 540
  • 662