To the R developers,

The discussion below reminded me that I think it might be a good idea
to take the Relevel function from the Lexis package and replace relevel
in stats with it. This is really nothing special for epidemiology.

It is fully compatible with the existing relevel (it actually contains
the
relevel code almost verbatim as a subset), but it has the extra
functionality
of combining levels.

I put the .R and .Rd files in
http://biostat.ku.dk/~bxc/R/suggest/
so please help yourself if you like.

Bendix Carstensen

-----Original Message-----
From: BXC (Bendix Carstensen) 
Sent: Wednesday, December 22, 2004 1:38 PM
To: '[EMAIL PROTECTED]'; 'R list'
Subject: RE: [R] ordering levels: I was wrong


I was wrong about needing the Relevel from the Lexis package.

The default verson of relevel does the job of reshuffling levels in any
desired order, albeit with a warning (which comes from the fact that
apparently only a single number had been anticipated by 
the designer):

> testf <- factor( sample( letters[1:4], 100, replace=T ) ) table( 
> testf, newf=relevel( testf, ref=c(3,2,1,4) ) )
     newf
testf c  b  a  d 
    a  0  0 21  0
    b  0 21  0  0
    c 32  0  0  0
    d  0  0  0 26
Warning message: 
the condition has length > 1 and only the first element will be used in:
if (is.na(ref)) stop("ref must be an existing level") 

Bendix Carstensen
----------------------
Bendix Carstensen
Senior Statistician
Steno Diabetes Center
Niels Steensens Vej 2
DK-2820 Gentofte
Denmark
tel: +45 44 43 87 38
mob: +45 30 75 87 38
fax: +45 44 43 07 06
[EMAIL PROTECTED]
www.biostat.ku.dk/~bxc
----------------------



> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of Anne
> Sent: Wednesday, December 22, 2004 1:06 PM
> To: R list
> Subject: [R] ordering levels
> 
> 
> Hello!
> I would like to know if there is a simple way to reorder
> levels of a given factor.Let's say  that the  vector
> testf<-factor(c("red","red","red","blue","blue","white")) 
>   levels(testf)  : blue red white 
> 
> should have reordered levels  such as
>  levels(testf)  : red blue  white 
> 
>  (this is for presentation purposes)
> I guess I'm looking for a generalized version of "relevel"...
> 
> Thanks
> 
> Anne
> 
> ----------------------------------------------------
> Anne Piotet
> Tel: +41 79 359 83 32 (mobile)
> Email: [EMAIL PROTECTED]
> ---------------------------------------------------
> M-TD Modelling and Technology Development
> PSE-C
> CH-1015 Lausanne
> Switzerland
> Tel: +41 21 693 83 98
> Fax: +41 21 646 41 33
> --------------------------------------------------
>  
>       [[alternative HTML version deleted]]
> 
> ______________________________________________
> [EMAIL PROTECTED] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read 
> the posting guide! http://www.R-project.org/posting-guide.html
>

______________________________________________
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to