Count every possible pair of values in a column grouped by multiple columns

前端 未结 7 2010
不知归路
不知归路 2020-12-03 15:59

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          


        
7条回答
  •  旧巷少年郎
    2020-12-03 16:44

    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)
    

提交回复
热议问题