Applying a Function over an Object in R Programming - sapply() Function Last Updated : 19 Jun, 2020 Comments Improve Suggest changes Like Article Like Report sapply() function in R Language takes list, vector or data frame as input and gives output in vector or matrix. It is useful for operations on list objects and returns a list object of same length of original set. Syntax: sapply(X, FUN) Parameters: X: A vector or an object FUN: Function applied to each element of x Example 1: Python3 # R program to illustrate # sapply function # Getting the value of Biochemical oxygen # demand data set BOD # Calling sapply() function which # will sum the data of each columns # of BOD sapply(BOD, sum) Output: Time demand 1 1 8.3 2 2 10.3 3 3 19.0 4 4 16.0 5 5 15.6 6 7 19.8 Time demand 22 89 Example 2: Python3 # R program to illustrate # sapply function # Initializing a list mylist <- list(c(1, 2, 3, 4), c(2, 4, 6, 8), c(1, 3, 5, 7)) # Calling the sapply() function which # will calculate mean of each vector elements sapply(mylist, mean) Output: [1] 2.5 5.0 4.0 Comment More infoAdvertise with us Next Article Applying a Function over an Object in R Programming - sapply() Function K Kanchan_Ray Follow Improve Article Tags : R Language R DataFrame-Function R Vector-Function R Object-Function R Matrix-Function R List-Function +2 More Similar Reads Apply a Function over a Ragged Array in R Programming - tapply() Function tapply() function in R Language is used to apply a function over a subset of vectors given by a combination of factors Syntax: tapply(vector, factor, fun) Parameters: vector: Created Vector factor: Created Factor fun: Function to be applied Example 1: Python3 1== # R Program to apply a function # ov 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 Concatenating Objects in R Programming - combine() Function In R programming, coercion function c() and combine() function are similar to each other but are different in a way. combine() functions acts like c() and unlist() functions but uses consistent dplyr coercion rules. Moreover, combine() function is used to combine factors in R programming. In this ar 2 min read Convert an Object to List in R Programming - as.list() Function as.list() function in R Programming Language is used to convert an object to a list. These objects can be Vectors, Matrices, Factors, and dataframes. Syntax: as.list(object) Parameters: object: Vector, Matrix, factor, or data frame R - as.list() Function ExampleExample 1: Converting Vector to list 2 min read Display the internal Structure of an Object in R Programming - str() Function str() function in R Language is used for compactly displaying the internal structure of a R object. It can display even the internal structure of large lists which are nested. It provides one liner output for the basic R objects letting the user know about the object and its constituents. It can be 3 min read Convert an Object into a Vector in R Programming - as.vector() Function as.vector() function in R Language is used to convert an object into a vector. Syntax: as.vector(x) Parameters: x: Object to be converted Example 1: Python3 1== # R program to convert an object to vector # Creating an array x <- array(c(2, 3, 4, 7, 2, 5), c(3, 2)) x # Calling as.vector() Function 1 min read Get or Set names of Elements of an Object in R Programming - names() Function names() function in R Language is used to get or set the name of an Object. This function takes object i.e. vector, matrix or data frame as argument along with the value that is to be assigned as name to the object. The length of the value vector passed must be exactly equal to the length of the obj 2 min read Convert an Object into a Matrix in R Programming - as.matrix() Function The as.matrix() function within R converts objects of various classes into a matrix. This can be helpful to work with structures of various data that can be converted into the matrix structure so that it becomes easier to analyze.Syntax: as.matrix(x)Parameters: x: Object to be convertedExample 1: Co 2 min read Looping over Objects in R Programming One of the biggest issues with the âforâ loop is its memory consumption and its slowness in executing a repetitive task. When it comes to dealing with a large data set and iterating over it, a for loop is not advised. In this article we will discuss How to loop over a list in R Programming Language 5 min read Convert a Vector into Factor in R Programming - as.factor() Function as.factor() function in R Programming Language is used to convert the passed object(usually Vector) into a Factor. Syntax: as.factor(object) Parameters: Object: Vector to be convertedas.factor() Function in R ExampleExample 1: Convert a Factor in RR # Creating a vector x<-c("female", "male", "ma 1 min read Like