0

my code so far looks like this, I have been trying to eliminate the letters in a new and old vector that repeat themselves. the letters represent emails. I have tried using unique and distinct functions, but they keep one of the duplicate values when I need to erase them all. this is the vector I would like as a result

c(b,c,e,f,t,r,w,u,p,q)
new <- c("a","b","c","d","e","f","t")
old <- c("r","w","u","a","d","p","q")
num <- c(1:7)
df_new <- data.frame(num, new)
df_old <- data.frame(num, old)

df_new <- transmute(df_new, num, emails = new)
df_old <- transmute(df_old, num, emails = old)

all_emails <- merge(df_new, df_old, all = TRUE)
Jilber Urbina
  • 53,125
  • 10
  • 108
  • 134
Albatross
  • 19
  • 4

1 Answers1

1

From what you show, you are complicating things unnecessarily by putting them in a data frame. Try this:

new <- c("a","b","c","d","e","f","t")
old <- c("r","w","u","a","d","p","q")
x = c(new, old)
result = x[!duplicated(x) & !duplicated(x, fromLast = TRUE)]
result
# [1] "b" "c" "e" "f" "t" "r" "w" "u" "p" "q"

Another method, if both your vectors are individually unique and you just need to drop everything that is in both new and old:

result = setdiff(union(new, old), intersect(new, old))
Gregor Thomas
  • 119,032
  • 17
  • 152
  • 277