0

Say, I have dataset

mydat=structure(list(x1 = structure(c(2L, 3L, 4L, 5L, 1L), .Label = c("", 
"a", "b", "c", "d"), class = "factor"), x2 = structure(1:5, .Label = c("a", 
"b", "c", "d", "e"), class = "factor")), .Names = c("x1", "x2"
), class = "data.frame", row.names = c(NA, -5L))

x1 has values a,b,c,d
x2 has values a,b,c,d,e

how can I display the values that there is in x2 var, but there is not in x1? In our case this is e-value

as output I desire

    Value
1   e

If this question is duplicate, please let me know, I'll delete it.

Dave2e
  • 22,192
  • 18
  • 42
  • 50
psysky
  • 3,037
  • 5
  • 28
  • 64

1 Answers1

1

We can try

setdiff(mydat$x2,mydat$x1)
[1] "e"
A. Suliman
  • 12,923
  • 5
  • 24
  • 37