I have two vectors:

```
x <- c(1,1,1,1,1, 2,2,2,3,3,  3,3,3,4,4,  5,5,5,5,5 )
y <- c(2,2,1,3,2, 1,4,2,2,NA, 3,3,3,4,NA, 1,4,4,2,NA)

```

This question ([Conditional calculating the numbers of values in column with R, part2](https://stackoverflow.com/questions/24331593/conditional-calculating-the-numbers-of-values-in-column-with-r-part2)) discussed how to find the number of values in `w` (don't count `NA`) for each `x` (from 1–5) and for each `y` (from 1–4).

Let's split `X` by groups: if `x<=2`, group `I`; if `2<x<=3`, group `II`; and if `3<X<=5`, group `III`. I need to find the number of different values in `x` by groups and by every value of `y`. I also need to find the mean of those values in `x` by the same groups. The output should be in this format:

```
y x    Result 1 (the number of distinct numbers in X); Result 2 (the mean)
1 I     ...
1 II    ...
1 III   ...     
...
4 I     ...
4 II    ...
4 III   ...

```