[R] Selecting groups with R

Peter Dalgaard p.dalgaard at biostat.ku.dk
Sat Aug 22 09:32:36 CEST 2009


David Winsemius wrote:

>>
>> How can I eliminate the BLUE category completely so I can do a t-test 
>> using
>> Color (with just the RED and WHITE subjects)?
> 
> dataset$Color <- as.character(dataset$Color)

or factor(dataset$Color), even.  As has been pointed out already, 
t.test.formula et al. do this internally, so there was really no problem 
to begin with.

BTW, the subsetting behaviour of factors is deliberate. It is not always 
by definition that some categories come out empty in a subgroup (think, 
e.g., a question in a questionnaire, stratified by age), and it is much 
easier to remove empty levels when you don't want them than to get them 
back in when you do.

-- 
    O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
   c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
  (*) \(*) -- University of Copenhagen   Denmark      Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)              FAX: (+45) 35327907




More information about the R-help mailing list