Skip to content
Prev 207337 / 398506 Next

How to apply a function on each column of a matrix

Here is the last code that I wrote but it would give me the same problem:
I have the matrix mat with n columns mat.1, mat.2 ...mat.n

#To be able to use lapply I convert it to a data.frame: 
mat <- data.frame(mat)

lapply(mat, function, argument of function)

It works but I still get for all elements the function applied for the last
element. The elements of my results are all the same I don't understand I
did exactly as shown on this website: 
http://www.ats.ucla.edu/stat/r/library/advanced_function_r.htm#lapply