options(scipen=999)
options(digits=9)
cat("\014") # clear screen
rm(list=ls(all=TRUE))



Prob.table=matrix(nrow=3,ncol=3,
         dimnames=list(c("y = 0","y = 1","y = 2"),
                       c("x = 0","x = 1","x = 2"))
         )
ncr=function(n,r) factorial(n)/(factorial(r)*factorial(n-r))
P=function(y,x) 
  if (x+y<=2) (ncr(3,x)*ncr(2,y)*ncr(3,2-x-y))/ncr(8,2) else 0

for (j in 1:3) 
{
  for (i in 1:3) 
  {
    Prob.table[i,j]=P(i-1,j-1)
  }
}
Prob.table



mdat <- matrix(c(1,2,3,4,5,6,7,8,9), nrow = 3, ncol = 3, byrow = TRUE,
               dimnames = list(c("row1", "row2","row3"),
                               c("C.1", "C.2", "C.3")))
mdat
