My sample data looks like:
time state district count category
2018-01-01 Telangana Nalgonda 17 Water
2018-01-01 Telangana Nalgonda 8 Irrigation
2018-01-01 Telangana Nalgonda 52 Seeds
2018-01-01 Telangana Nalgonda 28 Electricity
2018-01-01 Telangana Nalgonda 27 Storage
2018-01-01 Telangana Nalgonda 12 Pesticides
I've around 2 years of monthly data of different states and districts. I would like to melt the data to wide format
Tried :
one <- reshape(dataset,idvar = c("time","state","district"),v.names = names(dataset$category),
timevar = "count"
, direction = "wide")
Expected Output :
time state district Water Irrigation Seeds Electricity Storage Pesticides
2018-01-01 Telangana Nalgonda 17 8 52 28 27 12
I'm not sure how exactly reshape package works. I've seen many examples but couldn't figure it out right explanations. Can some one let me know what's wrong I'm doing.