An embedded and charset-unspecified text was scrubbed... Name: not available Url: https://stat.ethz.ch/pipermail/r-help/attachments/20040107/d7c07184/attachment.pl
generic name of variables
2 messages · SAULEAU Erik-André, Brian Ripley
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, ripley at stats.ox.ac.uk 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