Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Split an address separated by comma

Tags:

r

I have a data.frame of house sale transactions. At the moment the Address is in format.

  1 Accacia Avenue,This Town,This City,A10 1AA.

Is there a way I can split this into different columns in the data.frame removing the , at the same time?

I have created a separate vector for now just containing addresses.

The Address in stored in the Address column of the Dataframe - data.

head(data$Address)
[1] 22 Amesbury Road, Feltham (TW13 5HJ)
[2]Flat 11, Gloucester Court, Links Road, London (W3 0EW)

I need to split this into

"Address1", "Address2", "Address3"

and I also need to remove the postcode within () as I already have this in a separate field.

like image 206
Jennifer Neary Avatar asked May 11 '26 23:05

Jennifer Neary


1 Answers

library(tidyr)
df <- data.frame(address = c("1 Accacia Avenue,This Town,This City,A10 1AA"))
separate(df , address , c("country" , "town" , "city" , "street") , ",")



# country             town      city      street
# 1 Accacia Avenue This Town This City   A10 1AA

these are dummy columns you can change column names as per your address

like image 191
Nader Hisham Avatar answered May 14 '26 14:05

Nader Hisham



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!