I have capture-recapture data with variables Year, Date, ID, and Distance.moved such that:
> head(df)
Year ID Date Distance.moved
2012 2012-005 29-05-12 10
2012 2012-006 30-05-12 22
2013 2013-001 22-06-13 5
2013 2013-002 23-06-13 6
I want to add 0 occurrences to the distance moved column, to get values for events where they did not move, such as:
Year ID Date Distance.moved
2012 2012-005 29-05-12 10
2012 2012-005 30-05-12 0
2012 2012-006 29-05-12 0
2012 2012-006 30-05-12 22
2013 2013-001 22-06-13 5
2013 2013-002 22-06-13 0
2013 2013-002 23-06-13 6
2013 2013-001 23-06-13 0
So only adding 0s for dates that exist as events in the Date column, and have it grouped per year.
I tried to add a binary 1,0 column for occurrences as such:
df_occ <- df %>%
group_by(Date,Year, ID) %>%
summarize(occurrence=n()) %>%
as.data.frame()
but this just gives me occurrence values = 1 for all IDs