diff --git a/R/padVariable.r b/R/padVariable.r
index b97c1915772b58491b8a78de1f560820e81b2a6c..0f2b04f588985f10084c3cc48bdfb80815a6f252 100644
--- a/R/padVariable.r
+++ b/R/padVariable.r
@@ -10,11 +10,13 @@
 #' @examples
 #' pCode <- '10'
 #' correctPCode <- padVariable(pCode,5)
+#' pCodes <- c('100','1000','0','12345','1565465465465465')
+#' correctPCodes <- padVariable(pCodes,5)
 padVariable <- function(x,padTo){
+  if(padTo <= 1) return(x)
   numDigits <- nchar(x)
-  if ((padTo-numDigits)>0){
-    leadingZeros <- paste(rep("0",(padTo-numDigits)),collapse="",sep="")
-    x <- paste(leadingZeros,x,sep="")
-  }
+  padding <- padTo-numDigits
+  padingZeros <- sapply(padding[padding > 0], function(y) paste(rep("0",y),collapse="",sep=""))
+  x[padding > 0] <- paste(padingZeros,x[padding > 0],sep="")
   return(x)
 }