Re: [R] colMeans in a data.frame with numeric and character data

From: Dimitris Rizopoulos <>
Date: Thu, 27 Mar 2008 21:05:35 +0100

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.


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

Quoting Diogo André Alagador <>:

> 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: mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Thu 27 Mar 2008 - 20:13:10 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 27 Mar 2008 - 20:30:24 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive