Pairwise Calculations
Implements a logic to run pairwise calculations on the columns of a data.frame or a matrix.
PairApply(x, FUN = NULL, ..., symmetric = FALSE)
x |
a list, a data.frame or a matrix with columns to be processed pairwise. |
FUN |
a function to be calculated. It is assumed, that the first 2 arguments denominate x and y. |
... |
the dots are passed to FUN. |
symmetric |
logical. Does the function yield the same result for FUN(x, y) and FUN(y, x)? |
This code is based on the logic of cor()
and extended for asymmetric functions.
a matrix with the results of FUN.
Andri Signorell <andri@signorell.net>
PairApply(d.diamonds[,c("colour","clarity","cut","polish")], FUN = CramerV, symmetric=TRUE) # user defined functions are ok as well PairApply(d.diamonds[,c("clarity","cut","polish","symmetry")], FUN = function(x,y) wilcox.test(as.numeric(x), as.numeric(y))$p.value, symmetric=TRUE) # asymetric measure PairApply(d.diamonds[,c("colour", "clarity", "cut", "polish")], FUN = Lambda, direction = "row") # ... compare to: Lambda(x=d.diamonds$colour, y=d.diamonds$clarity, direction="row") Lambda(x=d.diamonds$colour, y=d.diamonds$clarity, direction="column") # the data.frame dfrm <- d.diamonds[, c("colour","clarity","cut","polish")] PairApply(dfrm, FUN = CramerV, symmetric=TRUE) # the same as matrix (columnwise) m <- as.matrix(dfrm) PairApply(m, FUN = CramerV, symmetric=TRUE) # ... and the list interface lst <- as.list(dfrm) PairApply(lst, FUN = CramerV, symmetric=TRUE)
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.