OneBite.Dev - Coding blog in a bite size

find the common elements in two arrays in R

Code snippet on how to find the common elements in two arrays in R

  common_matches <- intersect(array1, array2)

This code is used to find any elements that are in both array1 and array2. The first line of code creates a new object called common_matches and assigns it to the result of the intersect() function. This function takes two arrays (array1 and array2) as arguments and returns the common elements in them. In this case, if there are elements in both arrays, they will be stored in the newly created object, common_matches. In this way, you can easily find any elements that are in both of your arrays.

r