Thank you again for your reply. I think the 9th digit indeed is the culprit. Please have a look at the new data.
# New Toy Data
library(tidyverse)
df_new <- tibble(
x = c("303401110309080105010401", "30340111011005010102",
"47506440000000", "55000000000637", "00160070001398", "47506450000000",
"47506180000000", "97715929050042", "27902690022652", "970503470",
"0000024100298", "0", "001570098", "9770025215000", "97725320530072"),
wanted = c("03.0340111E23", "03.0340111E19", "004.750644E13",
"00000005.5E13", "0160070001398", "004.750645E13", "004.750618E13",
"9.77159291E13", "002.790269E13", "0000970503470", "0000024100298",
"0000000000000", "0000001570098", "9770025215000", "9.77253205E13"),
length_of_x = c(24L, 20L, 14L, 14L, 14L, 14L, 14L, 14L, 14L,
9L, 13L, 1L, 9L, 13L, 14L),
pos9 = c("0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "0", "", "8", "1", "5")
)
df_new
#> # A tibble: 15 x 4
#> x wanted length_of_x pos9
#> <chr> <chr> <int> <chr>
#> 1 303401110309080105010401 03.0340111E23 24 "0"
#> 2 30340111011005010102 03.0340111E19 20 "0"
#> 3 47506440000000 004.750644E13 14 "0"
#> 4 55000000000637 00000005.5E13 14 "0"
#> 5 00160070001398 0160070001398 14 "0"
#> 6 47506450000000 004.750645E13 14 "0"
#> 7 47506180000000 004.750618E13 14 "0"
#> 8 97715929050042 9.77159291E13 14 "0"
#> 9 27902690022652 002.790269E13 14 "0"
#> 10 970503470 0000970503470 9 "0"
#> 11 0000024100298 0000024100298 13 "0"
#> 12 0 0000000000000 1 ""
#> 13 001570098 0000001570098 9 "8"
#> 14 9770025215000 9770025215000 13 "1"
#> 15 97725320530072 9.77253205E13 14 "5"