Apply function for each Row in an R Data Frame

R Tutorial – We shall learn how to apply a function for each Row in an R Data Frame with an example R Script using R apply function.

For each Row in an R Data Frame

To call a function for each row in an R data frame, we shall use R apply function.

apply(data_frame, 1, function, arguments_to_function_if_any)

The second argument 1 represents rows, if it is 2 then the function would apply on columns.

Following is an example R Script to demonstrate how to apply a function for each row in an R Data Frame.

 

Conclusion :

In this R Tutorial, we have learnt to call a function for each of the rows in an R Data Frame.