On Wed, 7 Jan 2004, SAULEAU Erik-Andr� wrote: > Dear R-list, > > I wish a very happy new year and send you a little question: I have > different variables which names are m1, m2, m4, .., m10, ... and want to > obtain for example mean of each of them without typing each mean(m1), > mean(m2), .... What is the solution for decomposing names in mXX?
Without knowing exactly the pattern, let me guess nms <- ls(pattern="^m[0-9]+") sapply(nms, function(m) mean(get(m))) would do what you want. As Thomas Lumley often says, it is probably better to use a list rather than m1, m2, m4, .... -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595 ______________________________________________ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
