pairwise | R Documentation |
Pairwise application of a function to the columns of a matrix/data.frame or elements of a list
pairwise(x, FUN, ..., comm = FALSE)
x |
a matrix or data.frame |
FUN |
any function that takes two vectors as input and returns a single value |
... |
further arguments passed to FUN |
comm |
logical; is FUN commutative? If true, only the lower triangle, including the diagonal, is computed |
An n×n square matrix with n the number of columns
of x
.
similarity
for a few more examples
dtf <- data.frame(aa=c(1, 1, 2, 2, 3, 2, 4), bb=c(1, 1, 2, 3, 3, 3, 4), cc=c(3, 3, 2, 1, 1, 1, 1), dd=c(1, 2, 2, 2, 1, 1, 2)) # Root Mean Square Deviation pairwise(dtf, function(x, y) sqrt(mean((x-y)^2))) # using with cor.test() to accompany cor() pv <- pairwise(dtf, function(x, y) cor.test(x, y)$p.val) pvn <- 6^(1.1-pv)-5 pvn[pvn<1] <- 1 set_mar(1, 1, 1, 1) plot(0, xlim=c(0.5, 4.5), ylim=c(0.5, 4.5), cex=0, ann=FALSE, xaxt="n", yaxt="n") text(rep(1:4, 4), rep(4:1, each=4), t(round(cor(dtf), 2)), cex=pvn, col=c("black", "darkgrey")[(pv>0.1)+1]) https://rdrr.io/github/AkselA/R-ymse/src/R/pairwise.R
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.