In R I have a dataframe with index values as rownames (called index) that looks something like this:
index
[1] "F0000014" "F0000015" "F0000024" "F0000036" ...hundreds more
And I have a dataframe that has rownames values (called table) that looks something like this:
table
[1] "F0038001" "F0259700;F0259699.3" "F0259699;F0259700.4" "F0259247.4"
...thousands more
Many of the 'index' dataframe rownames will match values of the 'table' rownames, and these are the rows I would like to copy out of 'table' into a new 'match' dataframe.
The complication is that some rowname values of the table dataframe have sub-numbers (denoted with .#), and some are also multiple index values concatenated together with semicolons. So all I want to require for a match is that the index value being queried matches somewhere within the table value for it to be called as a matched row, and therefore copied to the 'match' dataframe.
I have tried something like this in R based on this previous Stacks post:
for(var in rownames(index))
{
match <- table[grep(var, rownames(table)), ]
}
But I get an "incorrect number of dimensions" error.
I believe the problem is something to do with mis-specifying the rownames of the table dataframe improperly in this command, as that is what is different about my request compared to those in the linked post. Though any further modification I try seems to be met with another error.
Any help would be very much appreciated as I cannot seem to find a syntax that works!
Thanks so much.
Andrew