Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 206209

R: Summarize rows per month

$
0
0

I have made a dataframe which has a column with dates and columns with numeric values. I want this dataframe to group itself by month and summerize all the numeric values from the other columns per corresponding month.

Here is my dataframe example:

capture.date  Test1  Test2  Test3
2016-03-18      0      1      1
2016-03-18      1      1      1
2016-03-20      2      1      1
2016-04-12      1      0      1

I already tried some code:

df %>% 
  group_by(capture.date) %>% 
  summarise_each(funs(sum))

and:

aggregate(df[2:4], by=df["capture.date"], sum)

but both of these options return dataframes which summarize by daily date instead of month. How can I make it summarize by month instead of by day?

desired output:

capture.date  Test1  Test2  Test3
2016-03         3      3      3     
2016-04         1      0      1

Viewing all articles
Browse latest Browse all 206209

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>