generating a vector of difference between two vectors

后端 未结 2 721
梦谈多话
梦谈多话 2020-12-04 21:58

I have two csv files, and each of which consists of one column of data

For instance, vecA.csv is like

id
1
2

vecB.csv is like

2条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-04 22:05

    You are looking for the function setdiff

    setdiff(vectorB$id, vectorA$id)
    

    If you did not want this reduced to unique values, you could create a not in function

    (kudos to @joran here Match with negation)

    '%nin%' <- Negate('%in%')
    
    vectorB$id[vectorB$id %nin% vectorA$id]
    

提交回复
热议问题