pairwise | R Documentation |
Apply a function to pairwise of all combinations in row or column of a matrix.
pairwise(X, margin = c(1, 2), FUN, ...)
X |
a matrix |
margin |
row (1) or column (2) to apply the function |
FUN |
the function to be applied, which has two arguments and only returns a single value. |
... |
optional arguments to FUN |
a matrix with the same number of row (margin = 1) or column (margin = 2) with the original matrix.
X <- matrix(c(1, 2, 3, 4,
1, 2, 5, 6,
1, 2, 5, 7), nrow = 4)
FUN <- function(x, y, na.rm = FALSE) {
sum(x != y, na.rm = na.rm)
}
pairwise(X, 2, FUN, na.rm = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.