Skip to content
Prev 42504 / 398506 Next

generic name of variables

On Wed, 7 Jan 2004, SAULEAU Erik-Andr? wrote:

            
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, ....