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
apply
4 messages · Jan M. Wiener, Sean Davis, Dimitris Rizopoulos +1 more
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
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