To find diff between 2 vectors - one of the answers mentioned was:
x[is.na(match(x,y))]
with x <- c(1,2,3,4); y <- c(2,3,4
.
Can someone please explain this answer in detail ?
To find diff between 2 vectors - one of the answers mentioned was:
x[is.na(match(x,y))]
with x <- c(1,2,3,4); y <- c(2,3,4
.
Can someone please explain this answer in detail ?
Just break it down to steps,
match(x,y) #If no match is found, it returns (by default) NA
#[1] NA 1 2 3
is.na(match(x,y)) #Thus, is.na will create a logical vector for NA values
#[1] TRUE FALSE FALSE FALSE
x[is.na(match(x,y))] #Using the above logical vector as index for x
#[1] 1