Re: [R] mean for each row

2008-03-17 Thread Matthias Kohl
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 [EMAIL PROTECTED] 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
  10.0  0.0  0.0  0.0  0.6  0.0  8.4  0.0 29.4  0.0   38.4
  20.0  0.0  1.8  0.0 22.4  0.0  0.2  0.4  0.8  0.0   25.6
  37.8  0.0  0.0 17.6  1.4  0.0  0.0  0.0  0.0  0.0   26.8
  42.2  0.8  0.4  0.0  0.2 11.2  1.4 33.2  0.0  0.0   49.4
  50.2  1.8  0.0  1.0  0.0  0.2  0.0 12.2  0.0 19.2   34.6
  60.0  0.0  0.0  1.0  0.0  0.0  0.0  2.2  0.0 14.6   17.8
  70.0  0.0  0.0  0.0  3.6  0.2  0.0  2.0  0.0  0.26.0
  80.0  0.0 10.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0   10.0
  90.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.00.0
  10   1.0  1.4  0.0  0.0  0.0  1.0  0.4  0.0  0.0  0.03.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.02.8
  15   0.0  0.0  0.0  2.2  1.4  0.0  0.0  0.0  0.0  0.03.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.02.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.20.4
  20   0.0  8.2  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.08.2
  21   0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.00.0
  22   0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.40.4
  23   0.0  0.0  0.0  0.0  0.0  0.0  0.0  1.2  0.0  0.01.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.09.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.04.8
  31   0.0  0.0  0.6  0.0  0.8  0.0  0.0  0.0  4.8  0.06.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@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@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.


Re: [R] mean for each row

2008-03-17 Thread Bill.Venables
You need to omit the last column, though:

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

for example.



-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
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 [EMAIL PROTECTED]
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
  10.0  0.0  0.0  0.0  0.6  0.0  8.4  0.0 29.4  0.0
38.4
  20.0  0.0  1.8  0.0 22.4  0.0  0.2  0.4  0.8  0.0
25.6
  37.8  0.0  0.0 17.6  1.4  0.0  0.0  0.0  0.0  0.0
26.8
  42.2  0.8  0.4  0.0  0.2 11.2  1.4 33.2  0.0  0.0
49.4
  50.2  1.8  0.0  1.0  0.0  0.2  0.0 12.2  0.0 19.2
34.6
  60.0  0.0  0.0  1.0  0.0  0.0  0.0  2.2  0.0 14.6
17.8
  70.0  0.0  0.0  0.0  3.6  0.2  0.0  2.0  0.0  0.2
6.0
  80.0  0.0 10.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
10.0
  90.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@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@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.

__
R-help@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.


[R] mean for each row

2008-03-16 Thread Roslina Zakaria
  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
10.0  0.0  0.0  0.0  0.6  0.0  8.4  0.0 29.4  0.0   38.4
20.0  0.0  1.8  0.0 22.4  0.0  0.2  0.4  0.8  0.0   25.6
37.8  0.0  0.0 17.6  1.4  0.0  0.0  0.0  0.0  0.0   26.8
42.2  0.8  0.4  0.0  0.2 11.2  1.4 33.2  0.0  0.0   49.4
50.2  1.8  0.0  1.0  0.0  0.2  0.0 12.2  0.0 19.2   34.6
60.0  0.0  0.0  1.0  0.0  0.0  0.0  2.2  0.0 14.6   17.8
70.0  0.0  0.0  0.0  3.6  0.2  0.0  2.0  0.0  0.26.0
80.0  0.0 10.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0   10.0
90.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.00.0
10   1.0  1.4  0.0  0.0  0.0  1.0  0.4  0.0  0.0  0.03.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.02.8
15   0.0  0.0  0.0  2.2  1.4  0.0  0.0  0.0  0.0  0.03.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.02.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.20.4
20   0.0  8.2  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.08.2
21   0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.00.0
22   0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.40.4
23   0.0  0.0  0.0  0.0  0.0  0.0  0.0  1.2  0.0  0.01.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.09.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.04.8
31   0.0  0.0  0.6  0.0  0.8  0.0  0.0  0.0  4.8  0.06.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@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.


Re: [R] mean for each row

2008-03-16 Thread Hesen Peng
How about rowSums(x)/ncol(x), where x is the matrix?


On Mon, Mar 17, 2008 at 1:48 PM, Roslina Zakaria [EMAIL PROTECTED] 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
  10.0  0.0  0.0  0.0  0.6  0.0  8.4  0.0 29.4  0.0   38.4
  20.0  0.0  1.8  0.0 22.4  0.0  0.2  0.4  0.8  0.0   25.6
  37.8  0.0  0.0 17.6  1.4  0.0  0.0  0.0  0.0  0.0   26.8
  42.2  0.8  0.4  0.0  0.2 11.2  1.4 33.2  0.0  0.0   49.4
  50.2  1.8  0.0  1.0  0.0  0.2  0.0 12.2  0.0 19.2   34.6
  60.0  0.0  0.0  1.0  0.0  0.0  0.0  2.2  0.0 14.6   17.8
  70.0  0.0  0.0  0.0  3.6  0.2  0.0  2.0  0.0  0.26.0
  80.0  0.0 10.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0   10.0
  90.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.00.0
  10   1.0  1.4  0.0  0.0  0.0  1.0  0.4  0.0  0.0  0.03.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.02.8
  15   0.0  0.0  0.0  2.2  1.4  0.0  0.0  0.0  0.0  0.03.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.02.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.20.4
  20   0.0  8.2  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.08.2
  21   0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.00.0
  22   0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.40.4
  23   0.0  0.0  0.0  0.0  0.0  0.0  0.0  1.2  0.0  0.01.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.09.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.04.8
  31   0.0  0.0  0.6  0.0  0.8  0.0  0.0  0.0  4.8  0.06.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@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.




-- 
彭河森 Hesen Peng
Department of Statistics, Fudan University, Shanghai, P. R. C.
Tel: Mobile 86-13052231416 Dormitory 86-21-65647724 Home 86-23-68207912
__
R-help@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.