Skip to contents

format_address() This function concatenates a selection of fields from a dataframe.

Usage

format_address(
  dataset,
  selection = c("address_number", "address_rep", "address_street", "commune_name")
)

Arguments

dataset

dataframe

selection

vector of colnames to be concatenated

Value

The function returns a vector from the concatenation. Each element of the concatenated columns will be separated by a space.

Details

The function was created to process the French national address database (BAN) but it can be used to concatenate several columns in any dataframe.

Examples


dataset = data.frame(
   address_number = c("1", "", "3", "35","", "7"),
   address_rep = c("","bis","","ter", "", ""),
   address_street = paste("street", LETTERS[1:6]), 
   commune_name = c("PARIS", "SETE", "LONDRES", "TOULOUSE", "LYON", "NICE")
)
dataset
#>   address_number address_rep address_street commune_name
#> 1              1                   street A        PARIS
#> 2                        bis       street B         SETE
#> 3              3                   street C      LONDRES
#> 4             35         ter       street D     TOULOUSE
#> 5                                  street E         LYON
#> 6              7                   street F         NICE

format_address(dataset)
#> [1] "1 street A PARIS"         "bis street B SETE"       
#> [3] "3 street C LONDRES"       "35 ter street D TOULOUSE"
#> [5] "street E LYON"            "7 street F NICE"         
format_address(dataset, selection = c("commune_name", "address_street"))
#> [1] "PARIS street A"    "SETE street B"     "LONDRES street C" 
#> [4] "TOULOUSE street D" "LYON street E"     "NICE street F"