我是R编程的新手,我知道我可以编写一个循环来执行此操作,但是我读的所有内容都表明,为了简单起见,最好避免循环并使用apply。mapply - 传递元素的行和列作为参数
我有一个矩阵,我想在矩阵中的每个元素上运行此函数。
cellresidue <- function(i,j){
result <- (cluster[i,j] - cluster.I[i,] - cluster.J[j,] - cluster.IJ)/(cluster.N*cluster.M)
return (result)
}
i= element row
j= element column
cluster.J is a matrix of column means
cluster.I is a matrix of row means
cluster.IJ is the mean of the entire matrix named cluster
我想不通的是我如何才能元素的行和列(我想应该用行()和塔COL()函数)mapply正在与以及如何通过这些参数适用于应用程序吗?
读取'chisq.test'中的代码以查看主程序如何执行类似过程可能有价值。 –