myapply: Given a matrix X, an integer MARGIN in c(1,2) indicating 1...

Description Usage Arguments Value Examples

View source: R/NguyenToolsnguyenPkgRfunctionsHW2.R

Description

Runs a function FUN along the MARGIN of a matrix X

Usage

1
myapply(X, MARGIN, FUN, ...)

Arguments

X

a matrix of any type

MARGIN

a binary value taking on '1' for rows or '2' for columns of a matrix

FUN

a function that operates along the MARGIN of the matrix X

Value

The output that is identical to what apply() function family would return

Examples

1
2
3
4
5
6
7
fred <- matrix(1:6, ncol = 2)
myapply(fred, 1, mean)
myapply(fred, 2, mean)
myapply(fred, 1, max)
myapply(fred, 2, max)
myapply(fred, 1, function(x) quantile(x, 0.75))
myapply(fred, 2, function(x) quantile(x, 0.75))

benjnguyen/NguyenTools documentation built on May 25, 2019, 3:22 p.m.