Ok, so lets take some simple data
A <- c(1997,2000,2000,1998,2000,1997,1997,1997)
B <- c(0,0,1,0,0,1,0,0)
df <- data.frame(A,B)
Now if we run the following
length(df$B[df$A==1997& df$B==0])
length(df$B[df$A==1997& df$B==1])
We get the counts of each unique A and B combinations.
But I want to output a results that will search for each unique
A value (representing a year) and output the sum of B (being binary). The results can be a data.frame or matrix. Any suggestions on how to tackle such a problem?