match.call Function in R (Example)

 

In this tutorial you’ll learn how to match arguments of a function using the match.call command in R.

The page consists of one example for the usage of the match.call command. To be more precise, the tutorial will contain this content:

Let’s start right away:

 

Creation of Exemplifying Data

We’ll use the data below as basement for this tutorial:

my_x <- 1:5                          # Create example vector
my_x                                 # Print example vector
# [1] 1 2 3 4 5

As you can see based on the previous output of the RStudio console, the example data is an integer vector ranging from 1 to 5.

 

Example: Argument Matching Using match.call() Function

In this example, I’ll demonstrate how to match arguments of a function call in R.

Consider the application of the mean function to our example vector as shown below:

mean(my_x)                           # Apply mean function
# [1] 3

As you can see in the previous R code, we have simply inserted the name of our data object within the mean function without specifying the name of the argument.

We can now use the match.call function to return our function call with more details:

match.call(mean, call("mean", my_x)) # Apply match.call to mean function
# mean(x = 1:5)

The previous output shows a modified version of our mean function call. The name of the used argument is shown (i.e. x), and the values assigned to this argument are shown as well (i.e. 1:5).

 

Video, Further Resources & Summary

Have a look at the following video on my YouTube channel. In the video, I demonstrate the examples of this tutorial.

 

The YouTube video will be added soon.

 

Furthermore, you could have a look at the other articles on my website. I have published several articles already.

 

At this point you should know how to use the match.call command in R. Let me know in the comments, if you have any additional 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.


Leave a Reply

Your email address will not be published.

Fill out this field
Fill out this field
Please enter a valid email address.

Menu
Top