[R] Applying multiple functions to one object

Karl Ove Hufthammer karl at huftis.org
Wed Feb 2 14:59:16 CET 2011


Dear list members,

I recall seeing a convenience function for applying multiple functions to 
one object (i.e., almost the opposite of 'mapply’) somewhere.
Example: If the function was named ’fun’ the output of

  fun(3.14, mode, typeof, class)

would be identical to the output of

  c(mode(3.14), typeof(3.14), class(3.14))

Is my memory failing me, or does such a function already exists in a 
package? Of course, it’s not difficult to define a summary function and 
apply this to the object, but writing, for example,

fun(x, mean, median, sd, mad)

to quickly show the relevant information is much more *convient*.


It would be even nicer with a function that could also handle vectors and 
lists of values, and output the result as data frames or matrices. Example: 

x = c("foo", "bar", "foobar")
fun(x, nchar, function(st) substr(st, 1 ,2) )

y = list(3, 3L, 3.14, factor(3))
fun(x, mode, typeof, class)

-- 
Karl Ove Hufthammer



More information about the R-help mailing list