[R] If statements for vectors

From: Laura Bonnett <L.J.Bonnett_at_warwick.ac.uk>
Date: Wed, 09 Apr 2008 22:07:49 +0100

Dear Sirs,

I am using both the Bioconductor adds on (Affy, AffyPLM,...) and the 'standard' R-package.

I am trying to select a list of genes which all have expression values below a certain threshold.
I have done this by creating a vector which has 0s where the expression is greater than the threshold and 1s where it is less than or equal to it. Multiplying this vector by the expression values produces a list of 0s and expression values below the threshold value.

However, now I need to remove the 0s. I thought that this would be relatively trivial but it appears it isn't!!!

The dimension of the list (with the 0s and values) is 506994. So I wrote the following:

for(i in 1:506994) {
if(exp2[i] > 0) {
exp3 <- append(1,exp2[i])


where exp2 is the vector of 0s and threshold values. However I have since discovered that 'if' does not work on vectors. The suggestions I have seen on this forum include 'ifelse' which I don't believe to be relevant in this situation and 'sapply' which again I don't think is relevant.

Can anyone therefore tell me how I can produce a new vector from an old one by removing the 0 entries?

Thank you for your help,

University of Warwick

        [[alternative HTML version deleted]]

R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Wed 09 Apr 2008 - 21:13:45 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 09 Apr 2008 - 23:30:27 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive