r - How can I return column title within data.frame only if it contains a value of interest? -
after I have a data.frame column containing many I'm trying to drag where For reference, Thanks for any help in this topic about Try: ! Example: This approach will work Whether you're working with 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
true
is present, for example, I would like to see the X4, X6, X7,
and X8
out, but all others were excluded. 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.
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
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"
matrix
or data .frame
.
Comments
Post a Comment