Why can't the chi squared test be calculated with a row of zeros? I have some trouble to calculate chi squared statistic with R. 
My data and code are:
tbl <- matrix(data = c(96, 1, 0, 107, 4, 0), nrow = 3, ncol = 2)  
chisq.test(tbl)

And result is: 
  Pearsons Chi-squared test  

data:  tbl
X-squared = NaN, df = 2, p-value = NA

Warning message:
In chisq.test(tbl) : Chi-squared approximation may be incorrect

If I use this online chi squared calculator, it calculates a chi squared statistic from my data.
Can someone can explain why R is not calculating the chi squared statistic from these data?
 A: It's worth reviewing the chi-squared statistic's calculation here.  First, we need the expected count for each cell.  Under the assumption of independence, this is the probability an observation will be in a given row times the probability the observation will be in a given column times the number of observations:
$$
E_{ij} = p_i\times p_j\times N
$$
Each cell's contribution to the $\chi^2$ statistic is the square of the observed count minus the expected count, divided by the expected count:
$$
{\rm cell\ contribution}_{ij} = \frac{(O_{ij}-E_{ij})^2}{E_{ij}}
$$
To get the $\chi^2$ statistic you add those up.  We can try this with your data using R:  
tbl = as.table(tbl)
tbl
#     A   B
# A  96 107
# B   1   4
# C   0   0
row.proportions = rowSums(tbl)/sum(tbl)
col.proportions = colSums(tbl)/sum(tbl)
row.proportions
#          A          B          C 
# 0.97596154 0.02403846 0.00000000
col.proportions
#         A         B 
# 0.4663462 0.5336538 
expected.values = t(t(row.proportions))%*%t(col.proportions)*sum(tbl)
expected.values
#            A          B
# A 0.45513591 0.52082563
# B 0.01121024 0.01282822
# C 0.00000000 0.00000000
cell.contributions = (as.vector(tbl)-as.vector(expected.values))^2 / 
                      as.vector(expected.values)
print(as.table(matrix(cell.contributions, nrow=3)), na.print="NaN")
#            A          B
# A 0.01873391 0.01637107
# B 0.76059675 0.66466563
# C        NaN        NaN

Because there are no observations in the third row of your table, the estimated probability of an observation being in that row is $0$.  From there we end up with expected counts of $0$ for those cells and we end up trying to divide by $0$ when we try to get the $\chi^2$ statistic.  
