Filter out rows from one data.frame that are present in another data.frame

前端 未结 3 1924
面向向阳花
面向向阳花 2020-12-24 02:29

Suppose I have a larger data.frame and a smaller one. If the smaller one is contained inside the larger one, how can I subtract the rows of the smaller data.frame, leaving a

3条回答
  •  独厮守ぢ
    2020-12-24 03:09

    In dplyr:

    library(dplyr)
    
    setdiff(BigDF, SmallDF)
    

    More Info: Hadley's dply cheatsheet: https://www.rstudio.com/wp-content/uploads/2015/02/data-wrangling-cheatsheet.pdf

    Concise Set Operations functions with examples http://rpackages.ianhowson.com/cran/dplyr/man/setops.html (But the entire Grammar of Data Manipulation is a great resource overall)

    And although the below is not in direct answer to your question - it is frequently related for me (and has been very useful)

    If you wish to capture the new changes that have occured between a new dataframe and a previous version of the same dataframe (inside the same records) you will want to make your code look as below:

    setdiff(NewDF, OldDF)
    

提交回复
热议问题