I have a data frame, and two of the columns are indices for another data fame. I want to add a column to the first by indexing the second, but just calling the column names isn't working. For example, if the first data frame is :
... Gene CellLine ...
KRAS HELA ...
BRCA1 T24 ...
and my second dataframe looks like
KRAS BRCA1 ...
HELA 5 3
T24 2 1
...
I want the output to look like
... Gene CellLine Dependency ...
KRAS HELA 5 ...
BRCA1 T24 1 ...
without having to loop through the lines because the first data frame is massive. That is, is there any function or package that would do the equivalent to
for (i in rownames(table1)){
table1[i, dependency] <- ifelse(table1[i,"Gene"] %in% rownames(table2) & table1[i,"CellLine"] %in% colnames(table2), table2[table1[i,"Gene"],table1[i,"CellLine"]], NA)
}
but faster?
Thanks!