Skip to content

mean for each row

4 messages · Roslina Zakaria, Hesen Peng, Matthias Kohl +1 more

#
Hi r-users,
How do find the mean for each row? Thank you in advance for your help.


          1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 Day Totals
1            0.0  0.0  0.0  0.0  0.6  0.0  8.4  0.0 29.4  0.0       38.4
2            0.0  0.0  1.8  0.0 22.4  0.0  0.2  0.4  0.8  0.0       25.6
3            7.8  0.0  0.0 17.6  1.4  0.0  0.0  0.0  0.0  0.0       26.8
4            2.2  0.8  0.4  0.0  0.2 11.2  1.4 33.2  0.0  0.0       49.4
5            0.2  1.8  0.0  1.0  0.0  0.2  0.0 12.2  0.0 19.2       34.6
6            0.0  0.0  0.0  1.0  0.0  0.0  0.0  2.2  0.0 14.6       17.8
7            0.0  0.0  0.0  0.0  3.6  0.2  0.0  2.0  0.0  0.2        6.0
8            0.0  0.0 10.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0       10.0
9            0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0        0.0
10           1.0  1.4  0.0  0.0  0.0  1.0  0.4  0.0  0.0  0.0        3.8
11           0.0  8.2  0.0  0.0  0.0  0.0  8.4  0.0  0.0  0.4       17.0
12          10.8  0.8  0.0  0.0  0.0  0.0  1.0  0.0  0.0  4.2       16.8
13          32.8  0.0  0.0  0.8  0.0  0.0  0.0  0.0  0.2  0.2       34.0
14           1.0  0.0  1.6  0.2  0.0  0.0  0.0  0.0  0.0  0.0        2.8
15           0.0  0.0  0.0  2.2  1.4  0.0  0.0  0.0  0.0  0.0        3.6
16           0.6  0.0  0.0  0.6 22.0  0.0  0.0  0.0  0.0  0.0       23.2
17           0.0  0.0  0.0  0.0  0.0  0.0  2.8  0.0  0.0  0.0        2.8
18           2.8  0.0  0.0  0.0  0.0  0.0  8.2  0.0  0.0  8.2       19.2
19           0.0  0.0  0.0  0.0  0.0  0.2  0.0  0.0  0.0  0.2        0.4
20           0.0  8.2  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0        8.2
21           0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0        0.0
22           0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.4        0.4
23           0.0  0.0  0.0  0.0  0.0  0.0  0.0  1.2  0.0  0.0        1.2
24           0.0  0.0  0.0  0.0  1.0  0.0  0.0  2.0  8.2  0.0       11.2
25           3.2  0.0  0.0  0.6  0.6  0.0  0.0  0.0 11.8  0.0       16.2
26           0.0  0.0 26.2  0.0 12.6  0.0  0.0  2.2  0.0  0.0       41.0
27           0.2  0.0 10.6  0.0  1.2  0.0  0.0  1.8  0.0  0.0       13.8
28           0.0  4.0  0.0  5.8  0.0  0.0  0.0  0.0  0.0  0.0        9.8
29           0.2 12.4  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0       12.6
30           0.0  2.6  0.0  0.0  2.2  0.0  0.0  0.0  0.0  0.0        4.8
31           0.0  0.0  0.6  0.0  0.8  0.0  0.0  0.0  4.8  0.0        6.2
Year Totals 62.8 40.2 51.2 29.8 70.0 12.8 30.8 57.2 55.2 47.6      457.6


      ____________________________________________________________________________________
Be a better friend, newshound, and
#
How about rowSums(x)/ncol(x), where x is the matrix?
On Mon, Mar 17, 2008 at 1:48 PM, Roslina Zakaria <zroslina at yahoo.com> wrote:

  
    
#
or rowMeans ...
Matthias
Hesen Peng wrote:

  
    
#
You need to omit the last column, though:

RowM <- rowMeans(x[, -ncol(x)])

for example.



-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
On Behalf Of Matthias Kohl
Sent: Monday, 17 March 2008 4:14 PM
To: Hesen Peng
Cc: R help forum
Subject: Re: [R] mean for each row

or rowMeans ...
Matthias
Hesen Peng wrote:
wrote:
help.
Totals
38.4
25.6
26.8
49.4
34.6
17.8
6.0
10.0
0.0
3.8
17.0
16.8
34.0
2.8
3.6
23.2
2.8
19.2
0.4
8.2
0.0
0.4
1.2
11.2
16.2
41.0
13.8
9.8
12.6
4.8
6.2
457.6
________________________________________________________________________
____________
http://www.R-project.org/posting-guide.html