[R] force output dimension of table function
Philipp Pagel
p.pagel at wzw.tum.de
Thu Apr 7 10:02:06 CEST 2011
On Thu, Apr 07, 2011 at 05:37:08AM +0200, fisken wrote:
> 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?
> And what I wanted was
>
> 0 1 2 3 4 5
> 0 1 1 1 0 2
The solution using factos has already been posted. if you are really
interested in integers only you could also use tabulate():
> tabulate(s)
[1] 1 1 1 0 2
Note that this excludes zero, though.
cu
Philipp
--
Dr. Philipp Pagel
Lehrstuhl für Genomorientierte Bioinformatik
Technische Universität München
Wissenschaftszentrum Weihenstephan
Maximus-von-Imhof-Forum 3
85354 Freising, Germany
http://webclu.bio.wzw.tum.de/~pagel/
More information about the R-help
mailing list