Count and Aggregate Date in R -


below data have:

item    date apple   09/06/2015 orange  19/06/2015 pear    01/09/2015 kiwi    20/10/2015 

i count items month , year in date column in r.

below output achieve:

date       frequency 05/2015    0 06/2015    2 07/2015    0 08/2015    0 09/2015    1 10/2015    1 

thank you.

just make sure have date in proper format, can use cut , table, plus formatting if want trim days,

## convert date dat$date <- as.date(dat$date, format="%d/%m/%y")  ## tabulate tab <- table(cut(dat$date, 'month'))  ## format data.frame(date=format(as.date(names(tab)), '%m/%y'),            frequency=as.vector(tab)) #      date frequency # 1 06/2015         2 # 2 07/2015         0 # 3 08/2015         0 # 4 09/2015         1 # 5 10/2015         1 

Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -