Imagine I have a data.frame (or matrix) with few different values such as this 

```
test <- data.frame(replicate(10,sample(c(-1,0,1),20, replace=T, prob=c(0.2,0.2,0.6))))   
test2 <- test

```

If I want to add extra columns with counts I could do: 

```
test2$good <-  apply(test,1, function(x) sum(x==1))   
test2$bad <-  apply(test,1, function(x) sum(x==-1)) 
test2$neutral <-  apply(test,1, function(x) sum(x==0))  

```

But If I had many possible values instead I would have to create many lines, it won't be elegant.

I've tried with table(), but the output is not easily usable

```
apply(test,1, function(x) table(x)) 

```

and there is a big problem, if any row doesn't contain any occurrency of some factor the result generated by table() doesn't have the same length and it can't be binded.

Is there way to force table() to take that value into account, telling it has zero occurrencies?

Then I've thought of using do.call or lapply and merge but it's too difficult for me.

I've also read about dplyr count but I have no clue on how to do it.
Could anyone provide a solution with dplyr or tidyr?

PD: What about a data.table solution?