Removing data from one dataframe that exists in another dataframe R

前端 未结 3 592
一整个雨季
一整个雨季 2021-02-10 03:31

I want to remove data from a dataframe that is present in another dataframe. Let me give an example:

letters<-c(\'a\',\'b\',\'c\',\'d\',\'e\')
numbers<-c(1         


        
3条回答
  •  清酒与你
    2021-02-10 03:32

    Base R Solution

    list_one[!list_one$letters %in% list_two$letters2,]
    

    gives you:

      letters numbers
    2       b       2
    5       e       5
    

    Explanation:

    > list_one$letters %in% list_two$letters2
    [1]  TRUE FALSE  TRUE  TRUE FALSE
    

    This gives you a vector of LENGTH == length(list_one$letters) with TRUE/FALSE Values. ! negates this vector. So you end up with FALSE/TRUE values if the value is present in list_two$letters2.

    If you have questions about how to select rows from a data.frame enter

    ?`[.data.frame`
    

    to the console and read it.

提交回复
热议问题