Input file:
df1 <- data.frame(row.names=c(\"w\",\"x\",\"y\",\"z\"),
A=c(0,0,0,0),
B=c(0,1,0,0),
C=c(1,
A shorter way (I think) using the amazing plyr package
Your data.frame
df1 <- data.frame(row.names=c("w","x","y","z"), A=c(0,0,0,0), B=c(0,1,0,0), C=c(1,0,1,0), D=c(1,1,1,1))
YOUR_COMBS<-combn(rownames(df1),2)
And your result :)
require(plyr) #(version 1.81...in version 1.82 you can take the annoying 'X1' index out... )
YOUR_RESULTS<-adply(YOUR_COMBS,2,function(x) {
tmp_row<-data.frame(Comb=paste0(x,collapse = ''),df1[x[1],]*df1[x[2],])
})