I need to find the common elements in vectors a & b and make a new vector c which contains these common elements, and afterward count the number of elements in c (i.e the number of common elements which in this case would be 1).
Is this what you are looking for?
a <- LETTERS[c(1:5, 10:15)]
b <- LETTERS[1:10]
intersect(a,b)
[1] "A" "B" "C" "D" "E" "J"
length(intersect(a,b))
[1] 6
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With