[R] Dummy newbie question

John Fox jfox at mcmaster.ca
Wed Apr 24 12:29:32 CEST 2002


Dear Julien,

Assuming that the data frame contains only numeric data, you can use apply: 
apply(data, 1, sum) will give you the row sums, and apply(data, 2, sum) the 
column sums.

John


At 09:49 AM 4/24/2002 +0200, Julien Barnier wrote:

>Excuse me for a so dummy question, but I really can't manage to do this
>very simple thing : I have a data frame, and I would like to calculate
>two vectors which contain the sums respectively of the rows and of the
>columns of the matrix.

-----------------------------------------------------
John Fox
Department of Sociology
McMaster University
Hamilton, Ontario, Canada L8S 4M4
email: jfox at mcmaster.ca
phone: 905-525-9140x23604
web: www.socsci.mcmaster.ca/jfox
-----------------------------------------------------

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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