-1

I have a vector:

table(FilterGenes)

FilterGenes

FALSE  TRUE 
 74     5

I'd like to see only TRUE names.

ruta
  • 1
  • 3
  • 3
    It is better to provide some example data as I am not sure what `datExpr` is. http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – akrun May 10 '15 at 19:39
  • @akrun my datExpr looks like: row.names Ens001 Ens002 X1 24.88857 28.11896 X2 25.03625 27.96043 – ruta May 11 '15 at 10:20
  • If you copy/paste the output in your R console, there will be error. – akrun May 11 '15 at 11:05
  • What I should do/change..? – ruta May 11 '15 at 11:14
  • I am not sure why you get a broken dput output For example. `ENSSSCG00000000062 = c(25.38918674, 25.1447644, 25.16140268, )` after the `,`, there is no element, also, the other columns have 6 elements – akrun May 11 '15 at 11:16
  • Can you try `names(datExpr)[col(datExpr)][FilterGenes]`. In the new dput, you have 6 columns with 6 column names. and I assume `FilterGenes` for this data would be of length `prod(dim(datExpr))` and want to extract the colnames for each TRUE value in the FilterGenes – akrun May 11 '15 at 11:19
  • > prod(dim(datExpr)) [1] 50940 – ruta May 11 '15 at 11:26
  • It would be, if you can post the `FilterGenes` for this example data and the expected result, it would be great. – akrun May 11 '15 at 11:27
  • I think I am completely lost about what you wanted. Your `datExp` original data is of dimension 30x1400 and the `FilterGenes` is 79. What is the expected output? – akrun May 11 '15 at 11:52
  • as you see, it's a vector: > table(FilterGenes) FilterGenes FALSE TRUE 74 5 – ruta May 11 '15 at 11:54
  • I understand that it is a vector, but what is your expected output? The reason why we ask for a reproducible example is to understand what you want. At present, I am completely clueless – akrun May 11 '15 at 11:55
  • datExpr contains names, as: "ENSSSCG00000000006" ..... >dimnames(data.frame(datExpr))[[2]][FilterGenes] shows me all 79 names, extracted from datExpr, but I want to get only the names which are TRUE.. – ruta May 11 '15 at 12:00
  • The solution I posted in the comment extract the names that are TRUE. – akrun May 11 '15 at 12:21
  • You mean by this...? >FilterGenes <- sample(c(TRUE, FALSE), 36, replace=TRUE) do not Works.. – ruta May 11 '15 at 12:32
  • That was just an example to find what your expected output is. It seems that we are both going in different directions. – akrun May 11 '15 at 12:45

1 Answers1

0

With respect to showing true values from the vector you could simply do:

ran.vec <- rep(c(F,T,F), 10)
ran.vec[ran.vec==TRUE]

I reckon that you want to filter your data frame by column having the true value. This could look like that:

data(mtcars)
mtcars$someTF <- mtcars$am == 1
mtcars[mtcars$someTF == TRUE,]
Konrad
  • 17,740
  • 16
  • 106
  • 167
  • Thank you @Konrad and I'm sorry, but I didn't get how to replace your example.. I was trying: >FilterGenes$someTF <- FilterGenes$am == 1 Error in FilterGenes$am : $ operator is invalid for atomic vectors... Would be also nice if you could be more precise in this as well: >ran.vec <- rep(c(F,T,F), 10) >ran.vec[ran.vec==TRUE] – ruta May 11 '15 at 08:52
  • @ruta if you could post a data extract, I trust, that this could be easily solved. I'm guessing that the structure of your vector is source of the problem, have a look at [the following discussion](http://stackoverflow.com/questions/23299684/r-error-in-xed-operator-is-invalid-for-atomic-vectors), it should help. – Konrad May 11 '15 at 09:53