[R] mean

Mark Myatt mark at myatt.demon.co.uk
Fri May 11 10:32:31 CEST 2001


luca laghi <llaghi at foodsci.unibo.it> writes:
>
> Greetings,
>a little question:
>if I heve got a matrix with 10 columns, how do I produce a 10 elements
>vector with the average of each column?
>Thank you,
>Luca

Try:

        apply(mat, 2, mean)

The '2' indicates columns. You can specify arguments to the applied
function ...

        apply(mat, 2, mean, na.rm = TRUE)

I hope that helps.

Mark

--
Mark Myatt


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list