symmetric_chr <- function(x) {
res <- sapply(x, function(x1){
sapply(x, function(x2) {i=length(intersect(na.omit(x1), na.omit(x2))); ifelse(is.na(i), 0, i)})
})
return(res)
}
#x <- data.frame(Samp1 = c(0,0,0,1,0,0,1,1,1), Samp2 = c(1,1,1,1,1,1,0,0,1))
x <- data.frame(Samp1 = c(letters[1:5],NA,NA), Samp2 = letters[1:7], sample3 = letters[10:16])
x
## Samp1 Samp2 sample3
## 1 a a j
## 2 b b k
## 3 c c l
## 4 d d m
## 5 e e n
## 6 <NA> f o
## 7 <NA> g p
symmetric_chr(x)
## Samp1 Samp2 sample3
## Samp1 5 5 0
## Samp2 5 7 0
## sample3 0 0 7