Question

I have columns of data like these:

adrs <- data.frame(address=rbind(c("CONFIDENTIST s.r.o. Ul. pri,Panoráme 26 945 01   Komárno"),
                   c("PD Dobrá Niva, a.s. Námestie,SNP 217/2 962 61   Dobrá Niva")))

and the desired outcome is:

new <- data.frame(rbind(cbind("CONFIDENTIST s.r.o.","Ul. pri,Panoráme 26","945 01","Komárno"),
                  cbind("PD Dobrá Niva, a.s.","Námestie,SNP 217/2","962 61","Dobrá Niva")))
colnames(new) <- c("Name","Street","PSC","Town")  

More in general: how to split and to create new columns after certain word occuring, in this example: after s.r.o. or a.s.

Was it helpful?

Solution

Here's now i might split after s.r.o. or a.s.

strsplit(gsub("(.*(?:s\\.r\\.o\\.|a\\.s\\.))\\s+(.*)","\\1;\\2",adrs$address),";")
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top