dataframe - R - removing rows from data frame according to a column in another data frame -


this question has answer here:

i have 2 data frames, 1 called athletes.df , 1 called medals.df. both have column named athlete_id unique key. problem have rows appear on medals.df table not in athletes.df, in case need remove them medals.df.

example of data:

athletes.df     athlete_id   v1  v2     'ttt'        5    6     '45d'        4    5     'tjd         4    5  medals.df        athlete_id   v3  v4     'ttt'        2    4     '45d'        5    5     'tjd         4    5     'err'        6    7 

if @ last row in medals.df has athlete_id of 'err' not appear in athletes.df,in case remove entire row.basicaly looking remove rows medals.df when thier athlete_id cannot found in ateletes.df table. know can done loop real data 30000 rows each data set , can take long time, way can done in efficient way?

this instruction you're looking for:

athletes.df <- athletes.df[athletes.df$athlete_id %in% medals.df$athlete_id, ] 

Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -