Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in R Programming by (7.3k points)
edited by

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?

1 Answer

0 votes
by
edited by

To find the elements of a vector, that are not present in another vector, you can use the setdiff() function as follows:

x <- c(1,2,3,4)

y <- c(2,3,4)

To find the elements of x that are not in y:

 setdiff(x, y)

[1] 1

To find the elements of y that are not in x:

setdiff(y,x)

numeric(0)

Browse Categories

...