VOOZH about

URL: https://www.geeksforgeeks.org/r-language/perform-operations-over-margins-of-an-array-or-matrix-in-r-programming-apply-function/

⇱ Perform Operations over Margins of an Array or Matrix in R Programming - apply() Function - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Perform Operations over Margins of an Array or Matrix in R Programming - apply() Function

Last Updated : 15 Jul, 2025
apply() function in R Language is used to perform mathematical operations across elements of an array or a matrix.
Syntax: apply(x, margin, func) Parameters: x: Array or matrix margin: dimension on which operation is to be applied func: operation to be applied
Example 1: Output:
 [, 1] [, 2] [, 3]
[1, ] 1 4 7
[2, ] 2 5 8
[3, ] 3 6 9
[1] 12 15 18
[1] 6 15 24
Example 2: Output:
 [, 1] [, 2] [, 3]
[1, ] 1 4 7
[2, ] 2 5 8
[3, ] 3 6 9
[1] 28 80 162
[1] 6 120 504
Comment

Explore