s-news
[Top] [All Lists]

Re: Removing levels from a factor

To: s-news@lists.biostat.wustl.edu, Mark.Hearnden@nt.gov.au
Subject: Re: Removing levels from a factor
From: Terry Therneau <therneau@mayo.edu>
Date: Wed, 5 Mar 2008 08:05:01 -0600 (CST)
Reply-to: Terry Therneau <therneau@mayo.edu>
 The easiest thing is to turn off factors:
 
 > options(stringsAsFactors=F)
 > data$Treatment <- as.character(data$Treatment)
 
 Now you can subset the data frame and things will work as you would anticipate.
 
 Comment: factors are occassionaly useful, but only occasionally.  Much grief 
can be avoided by turning them off by default.  Our biostat group (>100 people, 
over 1200 projects a year) has had the above option as a part of our global 
defaults for many years, and has not yet seen a downside to the decision.
 
        Terry Therneau
        Mayo Clinic

<Prev in Thread] Current Thread [Next in Thread>