[R] how to apply two or more functions to each columns in a time?

Yao He yao.h.1988 at gmail.com
Thu Dec 27 01:54:14 CET 2012


Dear All:

I want to calculate the mean and sd for each column in a data.frame.

Taking data(iris) for example:
I tried sapply(iris[,-5],mean,na.rm=T) or sapply(iris[,-5],sd,na.rm=T)
to calculate the mean and sd .But sapply() transfer a function per
time. How to transfer two functions in a time to generate a data.frame
like this:

           Sepal.Length Sepal.Width Petal.Length Petal.Width
mean    5.84333        3.05733        3.758000      1.199333
SD        0.82806        0.43586        1.765298       0.762237


Thanks a lot

Yao He

-- 
—————————————————————————
Master candidate in 2rd year
Department of Animal genetics & breeding
Room 436,College of Animial Science&Technology,
China Agriculture University,Beijing,100193
E-mail: yao.h.1988 at gmail.com
——————————————————————————



More information about the R-help mailing list