Show correlations as an ordered list, not as a large matrix

后端 未结 5 886
灰色年华
灰色年华 2020-12-02 13:22

I\'ve a data frame with 100+ columns. cor() returns remarkably quickly, but tells me far too much, especially as most columns are not correlated. I\'d like it to just tell m

5条回答
  •  萌比男神i
    2020-12-02 13:58

    Building off of @Marek's answer. Eliminates diagonal and duplicates

    data = as.data.frame( as.table( z ) )
    combinations = combn( colnames( z ) , 2 , FUN = function( x ) { paste( x , collapse = "_" ) } )
    data = data[ data$Var1 != data$Var2 , ]
    data = data[ paste( data$Var1 , data$Var2 , sep = "_" ) %in% combinations , ]
    

提交回复
热议问题