In matlab there is a way to find the values in one vector but not in the other.
for example:
x <- c(1,2,3,4)
y <- c(2,3,4)
is there any function that would tell me that the value in x
that's not in y
is 1?
In matlab there is a way to find the values in one vector but not in the other.
for example:
x <- c(1,2,3,4)
y <- c(2,3,4)
is there any function that would tell me that the value in x
that's not in y
is 1?
Yes. For vectors you can simply use the %in%
operator or is.element()
function.
> x[!(x %in% y)]
1
For a matrix, there are many difference approaches. merge()
is probably the most straight forward. I suggest looking at this question for that scenario.
you can use the setdiff() (set difference) function:
> setdiff(x, y)
[1] 1
The help file in R for setdiff, union, intersect, setequal, and is.element provides information on the standard set functions in R.