i want get expected value for matrix by Multiplication rowmarginal to colmarginal and divided sum of observed like folow this: observed<-matrix(c(1:20),ncol=2) expected=r