Hi, I have a simple question. If I have a table and I want to have the mean for each row, how can I do?! Es: c1 c2 c3 mean 1 12 13 14 ?? 2 15 24 10 ?? ... Thanks, Marco
> TABLE<-matrix(data=c(12,13,14,15,24,10),byrow=T,nrow=2,ncol=3) > TABLE[,1] [,2] [,3] [1,] 12 13 14 [2,] 15 24 10> apply(TABLE,1,mean)[1] 13.00000 16.33333 Chunhao Quoting Marco Chiapello <marco.chiapello at unito.it>:> Hi, > I have a simple question. If I have a table and I want to have the mean > for each row, how can I do?! > Es: > c1 c2 c3 mean > 1 12 13 14 ?? > 2 15 24 10 ?? > ... > > Thanks, > Marco > > ______________________________________________ > 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. >
On 6/6/2008 11:43 AM, Marco Chiapello wrote:> Hi, > I have a simple question. If I have a table and I want to have the mean > for each row, how can I do?! > Es: > c1 c2 c3 mean > 1 12 13 14 ?? > 2 15 24 10 ?? > ... > > Thanks, > MarcoVADeaths Rural Male Rural Female Urban Male Urban Female 50-54 11.7 8.7 15.4 8.4 55-59 18.1 11.7 24.3 13.6 60-64 26.9 20.3 37.0 19.3 65-69 41.0 30.9 54.6 35.1 70-74 66.0 54.3 71.1 50.0 rowMeans(VADeaths) 50-54 55-59 60-64 65-69 70-74 11.050 16.925 25.875 40.400 60.350 You could have found rowMeans() with the following: RSiteSearch("row means", restrict="functions")> ______________________________________________ > 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.-- Chuck Cleland, Ph.D. NDRI, Inc. (www.ndri.org) 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894
See also ?rowMeans On Fri, Jun 6, 2008 at 1:56 PM, <ctu at bigred.unl.edu> wrote:>> TABLE<-matrix(data=c(12,13,14,15,24,10),byrow=T,nrow=2,ncol=3) >> TABLE > > [,1] [,2] [,3] > [1,] 12 13 14 > [2,] 15 24 10 >> >> apply(TABLE,1,mean) > > [1] 13.00000 16.33333 > > Chunhao > > > Quoting Marco Chiapello <marco.chiapello at unito.it>: > >> Hi, >> I have a simple question. If I have a table and I want to have the mean >> for each row, how can I do?! >> Es: >> c1 c2 c3 mean >> 1 12 13 14 ?? >> 2 15 24 10 ?? >> ... >> >> Thanks, >> Marco >> >> ______________________________________________ >> 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. >> > > ______________________________________________ > 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. >