[R] How to apply a function on each column of a matrix
Jim Lemon
jim at bitwrit.com.au
Sun Jan 24 01:27:37 CET 2010
On 01/24/2010 11:11 AM, anna wrote:
>
> 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
Hi anna,
If you could post your matrix "mat" (or something else that produces the
problem you describe if "mat" is private or too big) and the commands
you used, someone will probably figure out what is going wrong.
Jim
More information about the R-help
mailing list