1

I have the following dataframe, df:

studID    Name
023       John
283       Mary
842       Jacob
211       Amy

and another dataframe, df_2:

studID
023
999
100
211
575

I want to subset the first dataframe, df so that it only contains the row values which the studID exists in the dataframe df_2.

So i would get:

studID    Name
023       John
211       Amy

This dataframe would only contain John and Amy record since their studID is found in df_2.

I tried the following:

df_3 <- df[intersect(df$studID, df_2$studID),]

But I'm getting N/A values.

1
  • 1
    df_3 <- df[df$studID %in% df_2$studID,] Commented Jan 18, 2022 at 7:56

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.