get consensus of multiple partitioning methods in R

后端 未结 2 670
野的像风
野的像风 2021-01-22 10:04

My data:

data=cbind(c(1,1,2,1,1,3),c(1,1,2,1,1,1),c(2,2,1,2,1,2))
colnames(data)=paste(\"item\",1:3)
rownames(data)=paste(\"method\",1:6)

I wan

2条回答
  •  一整个雨季
    2021-01-22 10:57

    You can try this, base R:

    res=apply(data,2,function(u) as.numeric(names(sort(table(u), decreasing=T))[1]))
    
    setNames(lapply(unique(res), function(u) names(res)[res==u]), unique(res))
    #$`1`
    #[1] "item 1" "item 2"
    
    #$`2`
    #[1] "item 3"
    

提交回复
热议问题