I know that some ICD9 codes contain letters, so I suspect that they are stored as "character". Here is a function that just pads zeros on to the end to make the string five characters long.
format <- function(icd9) { len <- length(strsplit(icd9, "")[[1]]) pad <- "" if (num <- 5-len) pad <- paste(rep("0", times=num), collapse="") paste(icd9, pad , sep="", collapse="") } Then use sapply() on the vector that contains the codes. Probably not too hard to stick a "." in there if you really want one. Darin On Tue, Jul 31, 2007 at 05:17:29PM +1200, Peter Alspach wrote: > > Kirsten > > One way to do this: > > kirsten <- c(123, 1234, 12345) > 100*as.numeric(paste(substring(kirsten, 1, 3), substring(kirsten, 4, 5), > sep='.')) > > HTH ........ > > Peter Alspach > > > > -----Original Message----- > > From: [EMAIL PROTECTED] > > [mailto:[EMAIL PROTECTED] On Behalf Of Kirsten Beyer > > Sent: Tuesday, 31 July 2007 9:31 a.m. > > To: r-help@stat.math.ethz.ch > > Subject: [R] simple coding question > > > > I have a list of ICD9 (disease) codes with various formats - 3 digit, > > 4 digit, 5 digit. The first three digits of these codes are > > what I am most interested in. I would like to either add > > zeros to the 3 and 4 digit codes to make them 5 digit codes > > or add decimal points to put them all in the format ###.##. > > I did not see a function that allows me to do this in the > > formatting command. This seems simple - can someone help? > > > > Thanks, > > K.Beyer > > > > ______________________________________________ > > 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. > > > > ______________________________________________________ > > The contents of this e-mail are privileged and/or confidenti...{{dropped}} > > ______________________________________________ > 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. ______________________________________________ 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.