Loop in matrix in a function

See ?lapply and then you should be able to adapt what I wrote in your previous question question, eg lapply(data, function)