Tell me how to create a function in arguments using apply() in R?

Submitted by: Muhammad
What if we want to be able to find how many data points (n) are in each column of m?

We are using columns, MARGIN = 2, thus, we can use length function to do this:

apply(my.matrx, 2, length)

There isn't a function in R to find n-1 for each column. So if we want to, we have to create our own Function. Since the function is simple, you can create it right inside the arguments for applying. In the arguments, I created a function that returns length – 1.

apply(my.matrx, 2, function (x) length(x)-1)

The function returned a vector of n-1 for each column.
Submitted by: Muhammad

Read Online Lead Data Scientist Job Interview Questions And Answers