I need to obtain the following "output" using the "table" below. My code below does not work. Appreciate if someone can give me a help. I tried the method mentioned in here but no luck to obtain the output I wanted.
Thanks.
table:
GRID_CODE sat_date pol my_id acres
0.1234 05_24_2019 12345 5 94.5
0.5678 05_24_2019 12345 5 94.5
0.1456 05_24_2019 12345 5 94.5
0.5895 05_24_2019 12345 5 94.5
1.2535 05_24_2019 12345 5 94.5
0.4878 05_24_2019 12345 5 94.5
0.2134 06_30_2019 12345 5 94.5
0.6178 06_30_2019 12345 5 94.5
0.1556 06_30_2019 12345 5 94.5
0.5895 06_30_2019 12345 5 94.5
0.2675 06_30_2019 12345 5 94.5
0.7188 07_15_2019 12345 5 94.5
0.8123 07_15_2019 12345 5 94.5
0.1788 07_15_2019 12345 5 94.5
0.9852 07_15_2019 12345 5 94.5
0.4528 07_15_2019 12345 5 94.5
0.7861 07_15_2019 12345 5 94.5
0.0541 07_15_2019 12345 5 94.5
My code below does not work. Appreciate if someone can give me a help.
library(data.table)
setDT(table)
output1 <- dcast.data.table(table, pol + my_id + acres ~ sat_date, fun.aggregate = identity, fill = NA_real_, value.var = "GRID_CODE")
pol my_id acres 05_24_2019 06_30_2019 07_15_2019
12345 5 94.5 0.1234 0.2134 0.7188
Aggregate function missing, defaulting to 'length'
I also tried this but it does not produce the desired output.
output2 <- reshape(out_p_sel, idvar = "pol", timevar = "sat_date", direction = "wide")
output:
pol my_id acres 05_24_2019 06_30_2019 07_15_2019
12345 5 94.5 0.1234 0.2134 0.7188
12345 5 94.5 0.5678 0.6178 0.8123
12345 5 94.5 0.1456 0.1556 0.1788
12345 5 94.5 0.5895 0.5895 0.9852
12345 5 94.5 1.2535 0.2675 0.4528
12345 5 94.5 0.4878 N/A 0.7861
12345 5 94.5 N/A N/A 0.0541