The following code works....
sum( (WASDATj$HCNT == 1 | WASDATj$HCNT == -1 | WASDATj$HCNT == 0 ) & WASDATj$Region=='United States'
& WASDATj$Unit=='Million Bushels'
& WASDATj$Commodity=='Soybeans'
& WASDATj$Attribute == 'Production'
& WASDATj$Fdex.x == 10
,na.rm=TRUE
)
It counts the number of observations where HCNT
takes a value of -1,1,0
it provides a single number for this category.
The variable WASDATj$Fdex.x
takes a value from 1-20.
How can I generalize this to count the number of observations that take a value -1,1,0
for each of the values of Fdex.x
(so provide me 20 sums for Fdex.x
from 1-20)? I did look for an answer, but I'm such a novice I may have missed what is an obvious answer....