Comparing character vectors in R to find unique and/or missing values

前端 未结 3 540
逝去的感伤
逝去的感伤 2021-02-01 19:32

I have two character vectors, x and y.

x <- c(\"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"g\")
y <- c(\"a\",      \"c\", \"d\", \"e\",      \"g\")
<         


        
3条回答
  •  时光取名叫无心
    2021-02-01 20:11

    I think this should work:

    x[!(x %in% y)]
    

    First it checks for all x that are not in y, then it uses that as an index on the original.

提交回复
热议问题