x <- matrix(rnorm(1000),ncol=6)
y <- matrix(rnorm(500),ncol=3)
x[x < 0] <- NA
y[y> 1] <- NA
count.pairwise(x)
count.pairwise(y)
count.pairwise(x,y)
## The function is currently defined as
function (x, y=NULL)
{
sizex <- dim(x)[2]
if (length(y)>0)
{sizey <- dim(y)[2]} else {sizey <- dim(x)[2]}
result <- matrix(1, nrow = sizey, ncol = sizex)
xnames <- names(x)
colnames(result) <- names(x)
if (((is.data.frame(y)) | (is.matrix(y)))) {
rownames(result) <- names(y) } else {rownames(result) <- names(x)}
if (length(y) ==0) {
for (i in 1:sizex) {
for (j in 1:(i)) {
result[j, i] <- sum((!is.na(x[, j])) & (!is.na(x[,
i])))
result[i, j] <- result[j, i]
}
}
} else {
for (i in 1:sizex) {
for (j in 1:sizey) {
result[j, i] <- sum((!is.na(x[, i])) & (!is.na(y[,
j])))
}
}
}
return(result) }
Run the code above in your browser using DataLab