I have long dataframe with this kind of data.
df <- read.table(text="
category month
1 1 2016-12
2 1 2016-12
3 1 2017-01
4 5 2016-11
5 5 2017-11
6 4 2017-12", header=TRUE)
I need to spread that data by month and create for each category new row. For spreading I usually use spread function, but I don't know how to deal with that adding new rows.
Result should be
category 11-2016 12-2016 1-2017 11-2017 12-2017
1 0 2 1 0 0
4 0 0 0 0 1
5 1 0 0 1 0