Skip to content
Prev 256041 / 398506 Next

force output dimension of table function

You can do it using factor:

s0<-factor(0:5)
s1<-sample(s0,5,re=T)
s1
   [1] 0 2 2 4 0
   Levels: 0 1 2 3 4 5

table(s1)
   s1
   0 1 2 3 4 5
   2 0 2 0 1 0

Good luck!