R: how to get row and column names of the true elements of a matrix?

前端 未结 3 990
隐瞒了意图╮
隐瞒了意图╮ 2021-01-12 02:06

I have a logical matrix x with named rows (\'a\' and \'b\') and named columns (\'10\', \'20\', \'30\', \'40\'). Let\'s say, this:

   10   20   3         


        
3条回答
  •  灰色年华
    2021-01-12 02:30

    You can directly use apply.

    apply(
      x, 1, 
      function(u) paste( names(which(u)), collapse="," ) 
    )
    

提交回复
热议问题