Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7129053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T11:12:09+00:00 2026-05-28T11:12:09+00:00

With the sample data > df1 <- data.frame(x=c(1,1,2,3), y=c(a,b,a,b)) > df1 x y 1

  • 0

With the sample data

> df1 <- data.frame(x=c(1,1,2,3), y=c("a","b","a","b"))
> df1
  x y
1 1 a
2 1 b
3 2 a
4 3 b
> df2 <- data.frame(x=c(1,3), y=c("a","b"))
> df2
  x y
1 1 a
2 3 b

I want to remove all the value pairs (x,y) of df2 from df1. I can do it using a for loop over each row in df2 but I’m sure there is a better and simpler way that I just can’t think of at the moment. I’ve been trying to do something starting with the following:

> df1$x %in% df2$x & df1$y %in% df2$y
[1]  TRUE  TRUE FALSE  TRUE

But this isn’t what I want as df1[2,] = (1,b) is pulled out for removal. Thank you very much in advance for your help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T11:12:09+00:00Added an answer on May 28, 2026 at 11:12 am

    Build a set of pairs from df2:

    prs <- with(df2, paste(x,y,sep="."))
    

    Test each row in df1 with similarly process for membership in the pairset:

    df1[ paste(df1$x, df1$y, sep=".") %in% prs , ]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Define: > dats <- list( df1 = data.frame(a=sample(1:3), b = as.factor(rep(325.049072M,3))), + df2 =
I'm using XOM with the following sample data: Element root = cleanDoc.getRootElement(); //find all
Sample data: !!Part|123456,ABCDEF,ABC132!! The comma delimited list can be any number of any combination
How can you use the following sample data either with a foreach or while
I'm trying to read in some sample data from an XML file in a
So I've transferred the core data code from Apple's sample Core Data / RSS
How should I remove sample data in the self.down method(s) for both the migrations
I have a csv file with following sample data. o-option(alphabetical) v-value(numerical) number1,o1,v1,o2,v2,o3,v3,o4,v4,o5,v5,o6,v6 number2,o1,v11,o2,v22,o3,v33,o44,v44,o5,v55,o6,v66 and
I have a text file with sample data which I want to put under
Some sample data: DECLARE @TARGET TABLE ( ID INT, value INT ) ; DECLARE

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.