[R] Apply a multi-variable function to a vector

Jeff Newmiller jdnewmil at dcn.davis.ca.us
Fri Sep 9 23:38:41 CEST 2016

Your architecture has a bad smell to me. For one thing you are mixing different units in the same vector but should be putting multiple instances of the same variable into one vector. Lists of vectors (data frames) are typically used when multiple variables need to be grouped.

Another problem is that you are constraining the names of the variables you pass to the function to be named the same as they are inside the function. This really limits your use of those functions.

There really is too much abstraction going on here.
Sent from my phone. Please excuse my brevity.

On September 9, 2016 12:44:52 PM PDT, Steve Kennedy <SKennedy at AnikaTherapeutics.com> wrote:
>I would like to define an arbitrary function of an arbitrary number of
>variables, for example, for 2 variables:
>func2 <- function(time, temp) time + temp
>I'd like to keep variable names that have a meaning in the problem
>(time and temperature above).
>If I have a vector of values for these variables, for example in the
>2-d case, c(10, 121), I'd like to apply my function (in this case
>func2) and obtain the result. Conceptually, something like,
>Is there a simple way to accomplish this, for an arbitrary number of
>variables?  I'd like something that would simply work from the
>definition of the function.  If that is possible.
>Steve Kennedy
>CONFIDENTIALITY NOTICE: This e-mail message, including
>R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>PLEASE do read the posting guide
>and provide commented, minimal, self-contained, reproducible code.

More information about the R-help mailing list