1

Basically, I have a gene dataset in which the rows are genes and columns are sequential time points of protein folding. I need a function to filter genes of a certain threshold value from others across the entire data set, not just for certain vectors. For example:

          alpha98 alpha105 alpha112 alpha119
YAL002W      0.22     0.58    -0.36     0.13
YAL003W      0.05     0.55    -0.08     0.33

Any help would be great.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
  • df[df$alpha98>threshold,] ? – juba Apr 07 '13 at 20:20
  • do you want the threshold applied to all genes, or just to a specific kind? If the gene exceeds the threshold, do you want to select the whole row or just that particular value? – Ricardo Saporta Apr 07 '13 at 20:21
  • Thanks, juba. I was wondering if there was a way to do this for the entire data set, not just the columns. I will specify this. –  Apr 07 '13 at 20:22
  • Ricardo, thanks for your suggestion for me to specify. I'm seeking a function that's applicable for the entire data set, not just for a particular vector. –  Apr 07 '13 at 20:25
  • @user2105555, then as Juba points out, you can simply use `myDF[myDF>threshold]` (without specifying a column) – Ricardo Saporta Apr 07 '13 at 20:32

1 Answers1

2

R is vectorized and R recycles. That means, that generally, something as simple as myDF > threshold will get you awfully close to what you need.

Specifically, it will give you a logical matrix of the same dimensions as your data.frame which will be TRUE when that cell in the DF exceeds the threshold (and FALSE otherwise).

You can then use that matrix as your tool to subset the data.frame.

myDF[myDF > threshold]  
Ricardo Saporta
  • 54,400
  • 17
  • 144
  • 178