O'Reilly logo

R Data Analysis Cookbook - Second Edition by Kuntal Ganguly

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works...

Step 1, creates a matrix and generates the row minimums for it:

  • The first argument for apply is a matrix or array.
  • The second argument (called margin) specifies how we want to split the matrix or array into pieces. For a two-dimensional structure, we can operate on rows as 1, columns as 2, or elements as c(1,2). For matrices of more than two dimensions, margin can be more than two and specify the dimension(s) of interest (see the There's more... section).
  • The third argument is a built-in or custom function. In fact, we can even specify an unnamed function in-line, as step 3 shows.

The apply function invokes the specified function with each row, column, or element of the matrix, depending on the second argument.

The return ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required