我是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'中的代碼以查看主程序如何執行類似過程可能有價值。 –