edit: Questions related to leading 0's don't help me, because 1) I need to add 0's in the middle of string 2) In each string, I need to add a different number of 0's (and I "don't know" this number, for now, I know what to do to find how many 0's ) and 3) I need to automate this because of the file size.
I have a really big file that contains three columns with id's. The file look like this (in R it's read as data frame):
ABCDEFG005504315643 ABCDEFG001504336101 ABCDEFG005392630156
ABCDEFG005328208783 ABCDEFG000360175030 ABCDEFG005347352265
ABCDEFG000117796830 ABCDEFG003145429820 ABCDEFG000330889848
All id should be 19 characters long, but some of them are shorter. I have to correct them so that they are 19 characters long by adding 0's after 7th character (after letters).
The problem is I don't know how many 0's I need to add in each case because some id's have 17 characters but some can have 15 and so on.
I know in which rows I have shorter id's (I used which()
and nchar()
functions to find it) and I have an idea of how to find how many 0 I need to add (19 - nachar()
), but there are two issues:
- how to use this to correct id's if I only know from which character 0's should be inserted (I don't know precisely between which and which character because of different lengths, so I only know "start")
- how to do this for a really big data frame - maybe something from apply family?
Thank you for all the help!