Specify Multiple Arguments in apply Functions in R Last Updated : 14 Sep, 2021 Comments Improve Suggest changes Like Article Like Report In this article, we will discuss how to specify multiple arguments in apply functions in the R programming language. apply() function is used to apply conditions to get the resultant data like mean of data, the sum of data, etc. Syntax: apply(data, margin, function, na.rm = TRUE) where, data is the input dataframemargin is used to specify the widthfunction is the function used to do some sort of computation on the datana.rm is the function that check for NA values (if TRUE = removes the NA values else will not remove). Dataframe in use: Let us first look at how apply function can be applied to a dataframe without additional arguments. Example: R program to use apply() without additional arguments R # create a dataframe with student subjects data=data.frame(subject1=c(90,89,70,NA), subject2=c(100,89,98,78), subject3=c(NA,67,78,98)) # display print(data) # use apply to find mean of each subject column apply(data, 2, mean) Output: Now let us pass multiple arguments to apply() function. For this na.rm is set to TRUE. It will first apply the required function on the dataframe and then remove NA values from it. Example: R program that uses multiple arguments in apply function R # create a dataframe with student subjects data=data.frame(subject1=c(90,89,70,NA), subject2=c(100,89,98,78), subject3=c(NA,67,78,98)) # display print(data) # use apply to get mean of each subjects apply(data, 2, mean,na.rm=TRUE) Output: Example: R program to get sum of each subject column by specifying multiple arguments in apply R # create a dataframe with student subjects data=data.frame(subject1=c(90,89,70,NA), subject2=c(100,89,98,78), subject3=c(NA,67,78,98)) # display print(data) # use apply to get sum of each subjects apply(data, 2, sum,na.rm=TRUE) Output: Example: R program to get minimum and maximum of each subject by specifying multiple arguments R # create a dataframe with student subjects data=data.frame(subject1=c(90,89,70,NA), subject2=c(100,89,98,78), subject3=c(NA,67,78,98)) # display print(data) print("=============Minimum marks============") # use apply to get minimum marks of each subjects apply(data, 2, min,na.rm=TRUE) print("=============Maximum marks============") # use apply to get maximum marks of each subjects apply(data, 2, max,na.rm=TRUE) Output: Comment More infoAdvertise with us Next Article Specify Multiple Arguments in apply Functions in R gottumukkalabobby Follow Improve Article Tags : R Language R Functions Similar Reads Apply a Function (or functions) across Multiple Columns using dplyr in R Data processing and manipulation are one of the core tasks in data science and machine learning. R Programming Language is one of the widely used programming languages for data science, and dplyr package is one of the most popular packages in R for data manipulation. In this article, we will learn h 10 min read Apply Function to data.table in Each Specified Column in R In this article, we are going to see that how to apply a function to data.table in each specified column in R Programming Language. The data.table library in R is used to create datasets and represent it in an organized manner. The library can be downloaded and installed into the working space using 3 min read Combine Arguments into a Vector in R Programming - c() Function c() function in R Language is used to combine the arguments passed to it. Syntax: c(...) Parameters: ...: arguments to be combined Example 1: Python3 1== # R program to cumulative maxima # Calling c() function x <- c(1, 2, 3, 4) x Output: [1] 1 2 3 4 Example 2: Python3 1== # R program to cumulati 1 min read Function Arguments in R Programming Arguments are the parameters provided to a function to perform operations in a programming language. In R programming, we can use as many arguments as we want and are separated by a comma. There is no limit on the number of arguments in a function in R. In this article, we'll discuss different ways 4 min read Apply function to each column of matrix in R In this article, we will explore a method to apply the function to each matrix column by using R Programming Language. How to apply the function to each column of the matrix The function 'apply()' is used to apply the function to each column of the matrix. By using these methods provided by R, it is 3 min read Apply function to each row in Data.table in R In this article, we are going to see how to apply functions to each row in the data.table in R Programming Language. For applying a function to each row of the given data.table, the user needs to call the apply() function which is the base function of R programming language, and pass the required p 1 min read How to Handle Invalid Argument Error in R Functions Handling invalid argument errors in R functions involves implementing proper input validation and providing informative error messages to users. In this guide, we'll explore common practices for handling invalid argument errors, along with examples in R Programming Language. Types of errors for Inva 3 min read Get the List of Arguments of a Function in R Programming - args() Function args() function in R Language is used to get the required arguments by a function. It takes function name as arguments and returns the arguments that are required by that function. Syntax: args(name) Parameters: name: Function name Returns: For a closure: Formal Argument list but with NULL body For 1 min read Recursively apply a Function to a List in R Programming - rapply() function rapply() function in R Language is used to recursively apply a function to a list. Syntax: rapply(object, f, classes = "ANY", deflt = NULL, how = c("unlist", "replace", "list")) Parameters: object: represents list or an expression f: represents function to be applied recursively classes: represents 3 min read Apply a function to each group using Dplyr in R In this article, we are going to learn how to apply a function to each group using dplyr in the R programming language. The dplyr package in R is used for data manipulations and modifications. The package can be downloaded and installed into the working space using the following command : install.p 4 min read Like