Hi, simple question I guess: the following line works well: aveBehav=c(apply(sdata, 2, mean)) However, I would like to pass an argument to the function mean, namely na.rm=TRUE Does anyone knows how to do this? Thanks in advance, Jan
On Apr 7, 2005, at 8:27 AM, malte wrote:> Hi, > > simple question I guess: > > the following line works well: > > aveBehav=c(apply(sdata, 2, mean)) > > However, I would like to pass an argument to the function mean, namely > na.rm=TRUE >apply(sdata,2,function(x) {mean(x,na.rm=TRUE)}) Sean
> From: malte > > Hi, > > simple question I guess: > > the following line works well: > > aveBehav=c(apply(sdata, 2, mean)) > > However, I would like to pass an argument to the function > mean, namely > na.rm=TRUE > > Does anyone knows how to do this?aveBehav <- apply(sdata, 2, mean, na.rm=TRUE) or more efficiently: aveBehav <- colMeans(sdata, na.rm=TRUE) Read ?apply and look at the "..." argument. If you don't understand how it works, try the example on that page. Andy> Thanks in advance, > > Jan > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > > >
try,
apply(sdata, 2, mean, na.rm=TRUE)
or
# assuming `sdata' is a matrix
colMeans(sdata, na.rm=TRUE)
I hope it helps.
Best,
Dimitris
----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven
Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/16/336899
Fax: +32/16/337015
Web: http://www.med.kuleuven.ac.be/biostat/
http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm
----- Original Message -----
From: "malte" <jan.wiener at tuebingen.mpg.de>
To: <r-help at stat.math.ethz.ch>
Sent: Thursday, April 07, 2005 2:27 PM
Subject: [R] apply
> Hi,
>
> simple question I guess:
>
> the following line works well:
>
> aveBehav=c(apply(sdata, 2, mean))
>
> However, I would like to pass an argument to the function mean,
> namely na.rm=TRUE
>
> Does anyone knows how to do this?
>
> Thanks in advance,
>
> Jan
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>
malte <jan.wiener at tuebingen.mpg.de> writes:> aveBehav=c(apply(sdata, 2, mean))aveBehav= apply(sdata, 2, mean, na.rm=TRUE) and ?apply will tell you about this. + seth
On 7 Apr 2005 at 14:27, malte wrote:> Hi, > > simple question I guess: > > the following line works well: > > aveBehav=c(apply(sdata, 2, mean))Hallo try aveBehav=c(apply(sdata, 2, mean, na.rm=T)) Cheers Petr> > However, I would like to pass an argument to the function mean, > namely na.rm=TRUE > > Does anyone knows how to do this? > > Thanks in advance, > > Jan > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.htmlPetr Pikal petr.pikal at precheza.cz