as.function Function in R (Example)
In this tutorial, I’ll show how to create a user-defined function using the as.function function in R.
The page consists of one example for the application of the as.function function. To be more specific, the article is structured as follows:
Let’s dive right in!
Example: Create User-Defined Function Using as.function() & alist()
This example explains how to convert a object returned by the alist function to a user-defined function.
Have a look at the following R code:
my_fun <- as.function(alist(x1 = , # Using as.function & alist x2 = , x1 * x2))
The previous R syntax has constructed a user-defined function that takes two arguments x1 and x2.
Let’s apply this function to some values:
my_fun(x1 = 3, x2 = 5) # Apply user-defined function # [1] 15
The previous output shows the result when setting the function arguments to x1 = 3 and x2 = 5, i.e. the value 15.
Video, Further Resources & Summary
I have recently released a video on my YouTube channel, which explains the R programming codes of this tutorial. You can find the video below:
The YouTube video will be added soon.
Additionally, you may read the related articles on this website. I have released several tutorials already.
- is.function & is.primitive Functions in R
- Make Object Created within Function Usable Outside
- List of R Commands
- All R Programming Tutorials
At this point you should have learned how to apply the as.function function in the R programming language. Tell me about it in the comments section, if you have further questions.
Subscribe to the Statistics Globe Newsletter
Get regular updates on the latest tutorials, offers & news at Statistics Globe.
I hate spam & you may opt out anytime: Privacy Policy.
Thank you!
Welcome to the Statistics Globe newsletter. From now on, I’ll send you regular emails about statistics, data science, AI, and programming with R and Python.
I’m Joachim Schork. On this website, I provide statistics tutorials as well as code in Python and R programming.
Statistics Globe Newsletter
Get regular updates on the latest tutorials, offers & news at Statistics Globe. I hate spam & you may opt out anytime: Privacy Policy.
Thank you!
Please check your email inbox and click the confirmation link to complete your subscription. If you don’t see the email within a few minutes, please also check your spam/junk folder.






