Ziwei Ziwei - 2 months ago 5x
R Question

a simple way to sum the value of certain rows in R

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?


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")