Skip to content

Keeping factors with zero occurrences in "table" output

3 messages · Achim Zeileis, Ravi Varadhan

#
On Wed, 20 Apr 2005 11:38:13 -0400 Ravi Varadhan wrote:

            
I think the cleanest way is to store the preferences as a "factor" and
tell R at the creation of that factor what the levels are, i.e.
  preference <- factor(preference, levels = 1:7)
Then calling
  table(preference)
will also report categories with 0 observations.
Z
#
Thanks very much to Achim Zeileis, Matt Weiner, and Andy Liaw for their
solution.  Declaring preferences as a "factor" worked!

Best,
Ravi.

--------------------------------------------------------------------------
Ravi Varadhan, Ph.D.
Assistant Professor,  The Center on Aging and Health
Division of Geriatric Medicine and Gerontology
Johns Hopkins University
Ph: (410) 502-2619
Fax: (410) 614-9625
Email:  rvaradhan at jhmi.edu
--------------------------------------------------------------------------