Hi! All, I am trying to fetch rows from a data frame which matches to first 2 columns of another data frame. Here is the example what I am trying to do: > ptable=read.table(file="All.txt",header=T,sep="\t") > ptable=as.matrix(ptable) > dim(ptable) [1] 9275 6 > head(ptable) Gene1 Gene2 PCC PCC3 PCC23 PCC123 [1,] "3813_f_at" "3884_f_at" "0.9956842" "0.9955455" "0.9956513" "0.9956171" [2,] "3884_f_at" "3813_f_at" "0.9956842" "0.9955455" "0.9956513" "0.9956171" [3,] "3491_f_at" "3709_f_at" "0.9952116" "0.9951588" "0.9951601" "0.9950864" [4,] "3709_f_at" "3491_f_at" "0.9952116" "0.9951588" "0.9951601" "0.9950864" [5,] "3371_f_at" "3594_f_at" "0.9946206" "0.9945342" "0.9946246" "0.9946592" [6,] "3594_f_at" "3371_f_at" "0.9946206" "0.9945342" "0.9946246" "0.9946592" > table=read.table(file="All_GPYeast_m.txt",header=T,sep="\t") > table=as.matrix(table) > dim(table) [1] 9275 6 > head(table) Gene1 Gene2 PCC PCC3 PCC23 PCC123 [1,] "3491_f_at" "3709_f_at" "0.9953142" "0.9950756" "0.9954676" "0.9952902" [2,] "3709_f_at" "3491_f_at" "0.9953142" "0.9950756" "0.9954676" "0.9952902" [3,] "3813_f_at" "3884_f_at" "0.9951781" "0.9953901" "0.9959256" "0.9958152" [4,] "3884_f_at" "3813_f_at" "0.9951781" "0.9953901" "0.9959256" "0.9958152" [5,] "3371_f_at" "3594_f_at" "0.9946130" "0.9938905" "0.9945572" "0.9945285" [6,] "3594_f_at" "3371_f_at" "0.9946130" "0.9938905" "0.9945572" "0.9945285"
Now, I wish to pick column 1&2 from 'ptable' and their coresponding columns from 'table' and store it in a variable. I did following and got error > PCC=apply(ptable[,c(1,2)],1,function(x)table[x[1],x[2]]) Error in FUN(newX[, i], ...) : subscript out of bounds I was expecting something like this >head(PCC) [1,] "3813_f_at" "3884_f_at" "0.9951781" "0.9953901" "0.9959256" "0.9958152" [2,] "3884_f_at" "3813_f_at" "0.9951781" "0.9953901" "0.9959256" "0.9958152" --------------------- --------------------- Please, help! regards Amit ______________________________________________ R-help@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.