This was what I was looking for.  I figured factor was the way to go, but I wasn't sure how to implement it.  
 
The car recommendation looks good too, but I want to try to stay away from having to download another package if I can.
 
Thanks
 
cn

________________________________

From: Martin Becker [mailto:martin.becker@mx.uni-saarland.de]
Sent: Fri 9/7/2007 10:55 AM
To: Cory Nissen
Cc: r-help@stat.math.ethz.ch
Subject: Re: [R] FW: variable format



Dear Cory,

I am not familiar with SAS, but is this what you are looking for?

divisionTable <- matrix(c(1, "New England",
                          2, "Middle Atlantic",
                          3, "East North Central",
                          4, "West North Central",
                          5, "South Atlantic",
                          6, "East South Central",
                          7, "West South Central",
                          8, "Mountain",
                          9, "Pacific"),
                        ncol=2, byrow=T)
a <- NULL
a$divisionOld <- c(0,1,2,3,4,5)
a$divisionNew <-
as.character(factor(a$divisionOld,levels=divisionTable[,1],labels=divisionTable[,2]))
a$divisionNew

[1] NA                   "New England"        "Middle Atlantic" 
[4] "East North Central" "West North Central" "South Atlantic"


Kind regards,

  Martin


Cory Nissen schrieb:
>       
>
> Anybody? 
>
>
> ________________________________
>
> From: Cory Nissen
> Sent: Tue 9/4/2007 9:30 AM
> To: r-help@stat.math.ethz.ch
> Subject: variable format
>
>
> Okay, I want to do something similar to SAS proc format.
>
> I usually do this...
>
> a <- NULL
> a$divisionOld <- c(1,2,3,4,5)
> divisionTable <- matrix(c(1, "New England",
>                           2, "Middle Atlantic",
>                           3, "East North Central",
>                           4, "West North Central",
>                           5, "South Atlantic"),
>                         ncol=2, byrow=T)
> a$divisionNew[match(a$divisionOld, divisionTable[,1])] <- divisionTable[,2]
>
> But how do I handle the case where...
> a$divisionOld <- c(0,1,2,3,4,5)   #no format available for 0, this throws an error.
> OR
> divisionTable <- matrix(c(1, "New England",
>                           2, "Middle Atlantic",
>                           3, "East North Central",
>                           4, "West North Central",
>                           5, "South Atlantic",
>                           6, "East South Central",
>                           7, "West South Central",
>                           8, "Mountain",
>                           9, "Pacific"),
>                         ncol=2, byrow=T)  
> There are extra formats available... this throws a warning.
>
> Thanks
>
> Cory
>
>       [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@stat.math.ethz.ch 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.
>  




	[[alternative HTML version deleted]]

