1

Iam rather new to R and have problem with indexing though I went through a number of tutorials.For instance in the following case I have a list of probenames with the corresponding significant p-values as follows

      unique.et.                                            pBH
1     AFFX-r2-P1-cre-5_at                                   1.646105e-14
2     AFFX-r2-P1-cre-3_at                                   1.752547e-14
3     AFFX-r2-Ec-bioD-5_at                                  2.426254e-14
127            267584_at                                    1.820809e-14
149            267562_at                                    1.646105e-14
200            267511_at                                    1.880226e-14

and the below is the original matrix from which I have to extract only the probes with significant p-Values so that I will get to have the signal intensity values.

AFFX-r2-P1-cre-2_at 12.16271 12.70304 12.16271 12.70304 12.16271
AFFX-r2-P1-cre-3_at 12.70304 12.28280 12.35039 12.38397 12.36304
AFFX-r2-P1-cre-5_at 12.28280 12.35039 12.38397 12.36304 12.16271

So if i consider the probe named AFFX-r2-P1-cre-5_at with p value 1.646105e-14 Iwould need to extract the same probe from a list of other probes along with the intensity values. I tried out but could not do it.

I would also like to ask you all if there are tutorials with clear examples so that i can understand the concept.

Andrie
  • 176,377
  • 47
  • 447
  • 496
Stacey John
  • 151
  • 3
  • 3
  • 13
  • 1
    Welcome to StackOverflow. If you made a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) that demonstrates your question / problem, we would find it easier to answer. At a minimum, read the linked answers, then use `dput()` to post your sample data. – Andrie Aug 14 '12 at 07:00
  • Look at `merge` function, for example. – DrDom Aug 14 '12 at 07:21

1 Answers1

1
#data.frame with significant cases
df1 <- read.table(text="      unique.et.                                            pBH
1     AFFX-r2-P1-cre-5_at                                   1.646105e-14
2     AFFX-r2-P1-cre-3_at                                   1.752547e-14
3     AFFX-r2-Ec-bioD-5_at                                  2.426254e-14
127            267584_at                                    1.820809e-14
149            267562_at                                    1.646105e-14
200            267511_at                                    1.880226e-14",header=T,stringsAsFactors=FALSE)

#all data
df2 <- read.table(text="AFFX-r2-P1-cre-2_at 12.16271 12.70304 12.16271 12.70304 12.16271
AFFX-r2-P1-cre-3_at 12.70304 12.28280 12.35039 12.38397 12.36304
AFFX-r2-P1-cre-5_at 12.28280 12.35039 12.38397 12.36304 12.16271",header=F,stringsAsFactors=FALSE)

#select cases of df2 that occur in df1
df2[df2$V1 %in% df1$unique.et,]
#                   V1       V2       V3       V4       V5       V6
#2 AFFX-r2-P1-cre-3_at 12.70304 12.28280 12.35039 12.38397 12.36304
#3 AFFX-r2-P1-cre-5_at 12.28280 12.35039 12.38397 12.36304 12.16271
Roland
  • 127,288
  • 10
  • 191
  • 288