I am trying to get some help with summarizing a dataframe.
My example df looks like this:
ID Zoo Last_date
ABC-DEF DENVER Oct_2017
ABC-DEF DENVER Oct_2017
ABC-DEF DENVER Nov_2017
ABC-DEF DENVER Nov_2017
ABC-DEF DENVER Nov_2017
HG-IJK MEMPHIS Jan_2018
JK-LMO MEMPHIS Feb_2018
The result should be
ID ZOO Oct_2017 Nov_2017 Jan_2019 Feb_2018
ABC-DEF DENVER 2 3 0 0
HG-IJK MEMPHIS 0 0 1 0
JK-LMO MEMPHIS 0 0 0 1
I tried looking at reshape2
using the melt
and cast
functions but I couldn't achieve the desired result.
I melted the data into long form
tempMelt <- melt(temp, id.vars = 1:2, na.rm = FALSE)
and cast using
casttemp <- dcast(aqm, "ID" + "Zoo" ~ value)