[R] mean for each row
Bill.Venables at csiro.au
Bill.Venables at csiro.au
Mon Mar 17 07:21:35 CET 2008
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:
> 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:
>
>> 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
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>>
>
>
>
>
--
Dr. Matthias Kohl
www.stamats.de
______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list