Writing Functions in R: Part 2
I skipped all the in-between bits of writing functions. Maybe I will return to them in the future.
But for now, I think it's super important to know how to apply a function once I have written it using what else but...
APPLY!!!
Basic syntax:
apply(as.matrix(some object which is not a matrix already), Starting Row, function)
For eg.
Out <- apply(as.matrix(list of element), 1, function)
But for now, I think it's super important to know how to apply a function once I have written it using what else but...
- The output of Apply can be a vector or array or list of values
- The input of Apply is always a matrix. So make sure to insert a "as.matrix" before anything you want to apply your function on.
Basic syntax:
apply(as.matrix(some object which is not a matrix already), Starting Row, function)
For eg.
Out <- apply(as.matrix(list of element), 1, function)