Hello,
All the above answers are great, but I thought I'd add my approach as well (just for the fun of it
). It very similar to @nirgrahamuk but I don't use the map function.
t <- c("t1", "t2", "t3", "t4", "t5", "t6")
a <- c(10,4,8,0,0,0)
b <- c(0,5,4,0,0,5)
c <- c(5,0,5,1,4,0)
myData = data.frame(t,a,b,c)
colComb = combn(colnames(myData[,-1]), 2)
check = myData[,colComb[1,]] > 0 & myData[,colComb[2,]] > 0
colnames(check) = paste0(colComb[1,],colComb[2,])
cbind(myData, ifelse(check == T, 1, 0))
#> t a b c ab ac bc
#> 1 t1 10 0 5 0 1 0
#> 2 t2 4 5 0 1 0 0
#> 3 t3 8 4 5 1 1 1
#> 4 t4 0 0 1 0 0 0
#> 5 t5 0 0 4 0 0 0
#> 6 t6 0 5 0 0 0 0
Created on 2022-05-27 by the reprex package (v2.0.1)
PJ