Re: [R] force output dimension of table function

From: Jorge Ivan Velez <jorgeivanvelez_at_gmail.com>
Date: Thu, 07 Apr 2011 01:37:43 -0400

Hi,

You might try

> table(factor(s, levels = 0:5))

0 1 2 3 4 5
0 1 1 1 0 2

HTH,
Jorge

On Wed, Apr 6, 2011 at 11:37 PM, fisken <> wrote:

> I have a small annoying problem.
>
> When I use the 'table' function on a simple vector it counts the
> number of occurences.
> So depending on the values of my input vector the function returns a
> class of type table with different lengths.
>
> Is there an easy way to tell the table function, the values to expect?
>
> That is
> #############
> > set.seed(0)
> > s<-sample(0:5,5,rep=T)
> > s
> [1] 5 1 2 3 5
> > ts<-table(s)
> > ts
> s
> 1 2 3 5
> 1 1 1 2
>
> ##############
>
> And what I wanted was
>
> 0 1 2 3 4 5
> 0 1 1 1 0 2
>
>
> Thanks
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

        [[alternative HTML version deleted]]



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Thu 07 Apr 2011 - 05:41:10 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 07 Apr 2011 - 06:30:27 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive