I have two data frames; mRNA
(here) and RPPA
(here). The mRNA
data frame has 1,212 columns, while the RPPA
data frame has 937 columns. All columns names in the RPPA
data frame appear also in the mRNA
data frame (but not in the same order). Within the columns, the values are different between the two data frames.
I want to create a new mRNA
data frame, which will contain the same columns as the RPPA
data frame, and will not contain the columns that do not appear in the ("old") mRNA
data frame.
An example:
mRNA <- data.frame(A=c(25,76,23,45), B=c(56,89,12,452), C=c(45,456,243,5), D=c(13,65,23,16), E=c(17:20), F=c(256,34,0,5))
RPPA <- data.frame(B=c(46,47,45,49), A=c(51,87,34,87), D=c(76,34,98,23))
The expected result would be:
> new.mRNA
B A D
56 25 13
89 76 65
12 23 23
452 45 16
I've tried converting the RPPA column names into a vector, and than use it with the command mRNA[col.names.vector]
, as described here, but it doesn't work. It gives the error undefined columns selected
.
Is there a quick way to do it (without functions, loops etc.)?