X<-list(40,c(80,160),c(160,80,400)) Y<-list(10,c(10,30),c(5,18,20)) Z<-c(1,2,3) as.data.frame(do.call("rbind",X))->x as.data.frame(do.call("rbind",Y))->y x*y*Z->r r[upper.tri(r)] <- 0 rowSums(r)