Extracting characters from a string

This is a simple task, but I'm finding myself confused when I look for help. I have a column that has the entire address, I want to split it into 2 columns. One column for the building number and the other with the street name. Building numbers have a various numbers of digits. How do I split this string? I've tried using string_extract or substrfunctions.

What I have

[1]
250 Maple Street
12 North Street
1594 Cherry Road
5 Washington Drive

What I want:

[1]         [2]
250        Maple Street
12         North Street
1594       Cherry Road
5          Washington Drive

You could use the separate function from the tidyr package.

library(tidyr)
DF <- data.frame(Address = c("250 Maple St.", "5 Spruce", "1563 Main"))
DF
#>         Address
#> 1 250 Maple St.
#> 2      5 Spruce
#> 3     1563 Main
DF <- DF |> separate(Address, into = c("Number", "Street"), extra = "merge")
DF
#>   Number    Street
#> 1    250 Maple St.
#> 2      5    Spruce
#> 3   1563      Main

Created on 2022-06-15 by the reprex package (v2.0.1)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.