I have 3 dataframes. I need to delete any rows whose rownames aren't present in all three of the dataframes. Rather than take the transpose, merge, split, and relabel the rows, I've been using this for the case of two dataframes:
df1 = df1[rownames(df1) %in% rownames(df2), ]
df2 = df2[rownames(df2) %in% rownames(df1), ]
Doing so makes df1 delete all of its rows that don't appear in the 2nd dataset and vice versa.
But how can I do this for 3 or 4 datasets? I need something like:
df1 = df1[rownames(df1) %in% c(rownames(df2), rownames(df3)), ]
But that seems to make it remove the rows that are not present for BOTH df2 and df3, whereas I need to remove the rows that are not present in df2 as well as any rows that aren't present in df3.
For e.g, if:
df1 has three rows, with rownames x1, x2, and x3
df2 has rows x2, x3, x4
df3 has rows x3, x4, x5
The only row common to all three is x3, so I want all the other rows removed from the three dataframes.