[R] Factor levels.

Christos Hatzis christos at nuverabio.com
Wed Oct 3 07:10:59 CEST 2007


Would

levels(fff) <- c("A","S","U")

not work?  Can you send an example?

-Christos 

> -----Original Message-----
> From: r-help-bounces at r-project.org 
> [mailto:r-help-bounces at r-project.org] On Behalf Of Rolf Turner
> Sent: Wednesday, October 03, 2007 12:58 AM
> To: r-help list
> Subject: [R] Factor levels.
> 
> 
> I have factors with levels ``Unit", "Achieved", and 
> "Scholarship"; I wish to replace these with "U", "A", and "S".
> 
> So I do
> 
> 	fff <- factor(fff,labels=c("U","A","S"))
> 
> This works as long as all of the levels are actually present 
> in the factor.  But if ``Scholarship'' is absent (as if often 
> is) then I get an error.
> 
> I can do a workaround such as
> 
> 	fff <- factor(c("U","A","S")[fff],levels=c("U","A","S"))
> 
> but this seems kludgy to me.
> 
> Is there a sexier way?
> 
> 			cheers,
> 
> 				Rolf Turner
> 
> 
> ######################################################################
> Attention:\ This e-mail message is privileged and 
> confidenti...{{dropped}}
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
>



More information about the R-help mailing list