I have two data frames (A and B), both with a column ‘C’. I want to check if values in column ‘C’ in data frame A exists in data frame B.
A = data.frame(C = c(1,2,3,4))
B = data.frame(C = c(1,3,4,7))
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Use
%in%as followsWhich will tell you which values of column C of A are in B.
What is returned is a logical vector. In the specific case of your example, you get:
Which you can use as an index to the rows of
Aor as an index toA$Cto get the actual values:We can negate it too:
If you want to know if a specific value is in B$C, use the same function: