'How to find elements the exist in both and how many times they appear

Can anyone tell me how to find the common elements and how many times they appear from multiple vectors?

a <- c("A","3","u","y","2")
b <- c("A","V","u","3","V","3")

It should look something like this A:3, 3:3, u:2



Solution 1:[1]

There's no significance to the partition into a and b - you can just concat them and call table:

> a <- c("A","3","u","y","2")
> b <- c("A","V","u","3","V","3")
> table(c(a,b))

2 3 A V u y 
1 3 2 2 2 1 

Solution 2:[2]

The < operator has more precedence than the && operator. Hence your statement will be computed as i && (i2 < 0). In this case i2 < 0 will be a boolean and i is an integer.

To solve this issue use the brackets as

(i < 0) && (i2 < 0)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ofek Shilon
Solution 2