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.843.0573333.7581.199333
On Thu, Mar 2
On Thu, Mar 27, 2008 at 3:05 PM, Dimitris Rizopoulos
<[EMAIL PROTECTED]> wrote:
> try this:
>
> dat <- data.frame(x = rnorm(10), y = rexp(10), z = letters[1:10])
> colMeans(data.matrix(dat[sapply(dat, is.numeric)]))
Alternatively
> sapply(dat, mean)
x y z
-0.5260131
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, Leuv
3 matches
Mail list logo