Diogo André Alagador
2008-Mar-27 19:22 UTC
[R] colMeans in a data.frame with numeric and character data
Hi all, I would like to know if it is posible by, someway, to get colMeans from a data.frame with numeric as well as character data, dispersed all over the object. Note that I would like to get colMeans neglecting character data. I am really in need of some function proceeding in that way… All the best Diogo André Alagador [[alternative HTML version deleted]]
Dimitris Rizopoulos
2008-Mar-27 20:05 UTC
[R] colMeans in a data.frame with numeric and character data
try this: dat <- data.frame(x = rnorm(10), y = rexp(10), z = letters[1:10]) colMeans(data.matrix(dat[sapply(dat, is.numeric)])) I hope it helps. Best, Dimitris ---- Dimitris Rizopoulos Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm Quoting Diogo Andr? Alagador <dalagador at armail.pt>:> Hi all, > > I would like to know if it is posible by, someway, to get colMeans from > a data.frame with numeric as well as character data, dispersed all over > the object. Note that I would like to get colMeans neglecting character > data. > > I am really in need of some function proceeding in that way> > All the best > > Diogo Andr? Alagador > > [[alternative HTML version deleted]] > >Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
Gabor Grothendieck
2008-Mar-27 20:26 UTC
[R] colMeans in a data.frame with numeric and character data
summaryBy in the doBy package can do that. The builtin iris data set has 4 numeric columns and one factor column:> library(doBy) > summaryBy(.~1, iris, fun = mean, keep = TRUE)Sepal.Length Sepal.Width Petal.Length Petal.Width 1 5.843333 3.057333 3.758 1.199333 On Thu, Mar 27, 2008 at 3:22 PM, Diogo Andr? Alagador <dalagador at armail.pt> wrote:> Hi all, > > I would like to know if it is posible by, someway, to get colMeans from > a data.frame with numeric as well as character data, dispersed all over > the object. Note that I would like to get colMeans neglecting character > data. > > I am really in need of some function proceeding in that way? > > All the best > > Diogo Andr? Alagador > > [[alternative HTML version deleted]] > > > ______________________________________________ > 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. > >