s-news
[Top] [All Lists]

Re: [S]: Padding numbers with zeros after the decimal point

To: Nicole DePriest Demers <ntd@stat.ohio-state.edu>
Subject: Re: [S]: Padding numbers with zeros after the decimal point
From: "Jeffrey J. Hallman" <m1jjh00@frb.gov>
Date: Fri, 26 Feb 1999 08:42:53 -0500
Cc: s-news@wubios.wustl.edu, Dionne Pratt <pratt@stat.ohio-state.edu>, m1jjh00@frb.gov
In-reply-to: "Your message of Thu, 25 Feb 1999 18:15:38 EST." <Pine.HPP.3.95.990225173212.9760A-100000@bayes.mps.ohio-state.edu>
Sender: owner-s-news@wubios.wustl.edu
Nicole:

Here's a function that will do what you want.

pad.string <- function(x, len = max(nchar(x)), padchar = " ", right = T){
  ## pads x to the right (default) or left with padchar to desired length
  if(nchar(padchar) != 1) 
    stop("nchar(padchar) != 1")
  template <- paste(rep(padchar, len), collapse = "")
  if(right)
    xpad <- paste(substring(template, 1 + nchar(x)), x, sep = "")
  else  
    xpad <- paste(x, substring(template, 1 + nchar(x)), sep = "")
  attributes(xpad) <- attributes(x)
  xpad
}

Jeff 
-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu.  To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message:  unsubscribe s-news

<Prev in Thread] Current Thread [Next in Thread>