[R] Re ading Functions that are in a Vector

baptiste auguie baptiste.auguie at googlemail.com
Mon Sep 28 12:42:29 CEST 2009


Also, have a look at each() in the plyr package,

library(plyr)
each(length, mean, var)(rnorm(100))


baptiste

2009/9/28 trumpetsaz <stephaniezimmer at gmail.com>:
>
> I am trying to write a function that will have an input of a vector of
> functions. Here is a simplistic example.
> sumstats <- c(mean,sd)
> sumstats[1]
> #Gives this error
> #> sumstats[1]
> #[[1]]
> #function (x, ...)
> #UseMethod("mean")
> #<environment: namespace:base>
>
> I thought about restricting the input to character variables such as the
> following
> sumstats2 <- c("mean","sd")
> Is there a way to change "mean" to the function mean?
> --
> View this message in context: http://www.nabble.com/Reading-Functions-that-are-in-a-Vector-tp25639720p25639720.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>




More information about the R-help mailing list