I have a table of user_id category pairs. Users can fall into several categories. I am trying to get a cross category count for every possible result. i.e. the number of users who were in category A, as well as category C, etc.
My source data is structured as follows:

I would like the results to look like this, showing a cross category:

How can this be done in R or MySQL? The data is pretty big.
Here is an example of data:
data <- structure(list(category = structure(c(1L, 2L, 2L, 1L, 3L, 3L,
2L, 1L, 3L, 2L, 2L, 2L, 3L, 1L, 1L, 3L), .Label = c("A", "B",
"C"), class = "factor"), user_id = c(464L, 345L, 342L, 312L,
345L, 234L, 423L, 464L, 756L, 756L, 345L, 345L, 464L, 345L, 234L,
312L)), .Names = c("category", "user_id"), class = "data.frame", row.names = c(NA,
-16L))
Any snippets of code, thoughts on approaches, features or recommendations of the package are welcome. Thank! -John