Skip to content

Instantly share code, notes, and snippets.

@nilforooshan
Last active September 26, 2024 22:26
Show Gist options
  • Save nilforooshan/dc8c51aa772bc31de87443af310160f8 to your computer and use it in GitHub Desktop.
Save nilforooshan/dc8c51aa772bc31de87443af310160f8 to your computer and use it in GitHub Desktop.
R: Remove leading 0s in an array of strings

Remove leading 0s in an array of strings

id <- c("00001","00010","00022","07432")
as.character(as.integer(id))
[1] "1"    "10"   "22"   "7432"
sub("^0+", "", id)
[1] "1"    "10"   "22"   "7432"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment