fork download
  1. df = data.frame(name_and_address = c("Mr. Smith12 Some street",
  2. "Mr. Jones345 Another street",
  3. "Mr. Anderson6 A different street",
  4. "1 digit is at the start",
  5. "No digits, sorry."))
  6.  
  7. df$name <- sub("^(?:(\\D*)\\d.*|.+)", "\\1", df$name_and_address)
  8. df$address <- sub("^\\D*(\\d.*)?", "\\1", df$name_and_address)
  9. df$name
  10. df$address
Success #stdin #stdout 0.25s 39148KB
stdin
Standard input is empty
stdout
[1] "Mr. Smith"    "Mr. Jones"    "Mr. Anderson" ""             ""            
[1] "12 Some street"          "345 Another street"     
[3] "6 A different street"    "1 digit is at the start"
[5] ""