Remove a subset of records from a dataframe in r
10,868
We can use anti_join
library(dplyr)
anti_join(df, another_df)
Or if this is based on the rownames
, then %in%
can be used for creating a logical index to subset the rows
df[!row.names(df) %in% row.names(another_df),]
Author by
SaikiHanee
Updated on June 14, 2022Comments
-
SaikiHanee almost 2 years
We can combine 2 dataframes using
df = rbind(df, another_df)
. How it should be if its required to removeanother_df
fromdf
where rownames ofdf
andanother_df
are not matching.df = data.frame(A=c('a','aa','aaa'), B=c('b','bb','bbb')) rownames(df) another_df =data.frame(A=c('aa','a'), B=c('bb','b')) rownames(another_df)=c('3','4')