0

I don't know if the question has been asked already, but could not find the right answer. I have strings in a column with countrycodes, countrynames and a date, with no delimiters:

tst <- c("NLNETHERLAND2018-01-19","IRQIRAQ1912-02-28")

How could I split the strings that there are spaces between countrycode en the country name.

Because the countrycode varies in length (can be one character, two or three characters) it is not possible two split based on amount of characters.

C Visser
  • 1
  • 2
  • Hard to do, since two-letter countrycodes (NL) are mixed with three-letter contrycodes(IRQ), and some country-names are not correct (Netherland" does not exist.. it is "Netherlands" ... You need either a list of all country-names, or a list of all used countrycodes to perform your checks on. – Wimpel Sep 10 '18 at 11:31
  • 1
    do you have a full list of countrycodes and countrynames that will be in the data? If so, i would approach this by gsubing the "countryname" by "\_countrynyme\_" (\_ beeing the desired delimiter). This way you do not have to take care about the length of countrycode. A short example for netherland, just to describe what i mean: gsub("NETHERLAND", "\_NETHERLAND\_", "NLNETHERLAND1994-01-19") – TinglTanglBob Sep 10 '18 at 11:53

0 Answers0