unfortunately you give no code, nor any other information so it is not easy to help you. But as a start, here is a suggestion. 
From the error code you are given, it seems your data has duplicate values, or something like that. 
What I would suggest is the following, assuming that D is your data.frame:
library(data.table)
D=data.table(D)
D=D[,lapply(.SD,sum),by=c('state','prod_year')]
dcast.data.table(D,state~prod_year, value.var='num_oil_wells')
Now, there is a better way to do that, and without using data.table, but I don't remember exactly how to use it (using dcast, and aggregate). But I hope this is a good start.