Using apply with a different function argument for each element's evaluation
问题 Let's say I have a matrix, mat. mat <- matrix(1:5, nrow = 10, ncol = 3, byrow = TRUE) And I have some sort of function that I want to apply, in this case by column. getRMSE <- function(true, est) { sqrt(mean((true - est)^2)) } (This function is just the most recent example, but I've had this exact same conundrum at least 5 more times.) If you want to apply a function over a matrix, you use apply. But what if you want to apply a function over a matrix with different values for 'x' in the apply