To find the common values between two or more vectors in R, we can use the intersect() function. This function takes two or more vectors as arguments and returns a vector containing the values that are common to all of the input vectors.
Here's an example that demonstrates the use of intersect() to find the common values between two vectors:
main.r112 chars7 lines
Output:
main.r10 chars2 lines
In this example, vec1 and vec2 have three common values (3, 4, and 5). We use intersect() to find those common values and store the result in the common_values variable. Finally, we print the contents of common_values to the console.
gistlibby LogSnag