r - How can I return column title within data.frame only if it contains a value of interest? -


itemprop = "text">

after

I have a data.frame column containing many correct and false logical response, like this:

  & gt; [X] X1 X2 X3 X4 X5 X6 X7 X8 [1] false false false right wrong wrong false [2,] false false false false false false false true [3] false false false false false false false false [4,] false false false False false false false false [6,] false false false false [6,] false false false false false right [7,] false false false false  

I'm trying to drag where true is present, for example, I would like to see the X4, X6, X7, and X8 out, but all others were excluded.

For reference, true indicates that the cell is answering the stimuli at that specific time point. I just need to know that the cell responds at all (i.e. TRUE is present in at least one column), when the cell is unresponsive.

Thanks for any help in this topic about

Try: !

  colnames (m) [colSums (m) & gt; = 1]  

in colsums will be the sum of values, which can then be compared with the value of that. To remove 1 column name

Example:

  M & lt; - Matrix (FALSE, Nrow = 4, ncol = 5, dimnames = list (zero, paste0 ("x", 1: 5)) m [cbind (c (1, 2, 3, 4), c (2, 2 , 4, 5)) & lt; - TRUE M # X1 X2 X3 X4 X5 # [1,] Incorrect wrong wrong wrong # [2,] Incorrect wrong wrong wrong # [3] false false false right # [4] ,] False false false false true colnames (M) [colSums (M)> = 1] # [1] "X2" "X4" "X5"  

This approach will work Whether you're working with matrix or data .frame .


Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -