text: Q:
  
  Adding leading 0s in r
  
  I have a large data frame that is filled with characters such as:
   x <- c("Y188","Y204" ,"Y221","EP121_1" ,"Y233" , "Y248" ,"Y268", "BB2","BB20",  
   "BB32" ,"BB044" ,"BB056" , "Y234" , "Y249" ,"Y271" ,"BB3", "BB21", "BB33",
   "BB045","BB057" ,"Y236", "Y250", "Y272" , "BB4", "BB22" )
  
  As you can see, certain tags such as BB20 only have two integers. I would like the entire list of characters to have at least 3 integers like this(the issue is only in the BB tags if that helps):
  Y188, Y204, Y221, EP121_1, Y233, Y248, Y268, BB002, BB020, BB032, BB044,
  BB056, Y234, Y249, Y271, BB003, BB021, BB033, BB045, BB057, Y236, Y250,
  Y272, BB004, BB022 
  
  Ive looked into the sprintf and FormatC functions but still am having no luck.  
  
  A:
  
  A forceful approach with a nested gsub call:
  gsub("(.*[A-Z])(\\d{1}$)", "\\100\\2",
       gsub("(.*[A-Z])(\\d{2}$)", "\\10\\2", x))
  # [1] "Y188"    "Y204"    "Y221"    "EP121_1" "Y233"    "Y248"    "Y268"    "BB002"   "BB020"  
  # [10] "BB032"   "BB044"   "BB056"   "Y234"    "Y249"    "Y271"    "BB003"   "BB021"   "BB033"  
  # [19] "BB045"   "BB057"   "Y236"    "Y250"    "Y272"    "BB004"   "BB022"
  
  