Minus operation of data frames

前端 未结 7 722
忘掉有多难
忘掉有多难 2020-12-05 18:53

I have 2 data frames df1 and df2.

df1 <- data.frame(c1=c(\"a\",\"b\",\"c\",\"d\"),c2=c(1,2,3,4) )
df2 <- data.frame(c1=c(\"         


        
相关标签:
7条回答
  • 2020-12-05 19:23

    You can check the values in both columns and subset like this (just adding another solution):

    na.omit( df1[ sapply( 1:ncol(df1) , function(x) ! df1[,x] %in% df2[,x] ) , ] )
    #  c1 c2
    #1  a  1
    #2  b  2
    
    0 讨论(0)
提交回复
热议问题