I have a dataframe that looks like this (this is just a subset, actually dataset has 2724098 rows)
> head(dat) chr start end enhancer motif chr10
What about this?:
res1<- split(dat$motif,dat$id) res2<- lapply(res1,function(x) combn(x,2)) res3<- apply(do.call(cbind,res2),2,function(x) paste(x[1],x[2],sep="_")) table(res3)