How to split data monthly in R -


i have dataset corresponding register of buys in store, this:

date          buyid      price     description    category 2010-01-01    101028        100    ...            ... 2010-01-01    101028        100    ...            ... 2010-01-01    101028        100    ...            ... 2010-01-01    101028        100    ...            ... ... 

the dates in dataframe goes 2010-01-10 2015-04-01 , split monthly can plot volume of buys per month in each year, mean like:

date        count 2010-jan    19128 2010-feb    1232 ... ... 2015-mar    28363 2015-apr    12834 

i've been having hard time specially because i'm pretty new r , don't know many functions.

i tried split data using split couldn't make it. have clue how can this?

you can use dplyr this:

df %>%   mutate(new.date = cut.date(as.date(date, format = '%y-%m-%d'), "month")) %>%   group_by(new.date) %>%   summarise(count = n()) 

mutate create new column cutted dates, group_by month , summarise count number of entries.


also, if need year , abbreviation month, add 1 more mutate:

 %>% mutate(new.date = format(as.date(new.date), "%y-%b")) 

Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -