Skip to contents

Subset dataset with scope

Usage

select_scope(dataset, scope)

Arguments

dataset

dataframe or sf object, the dataset to scope

scope

character vector. Municipality french INSEE code called "Code Officiel Géographique" (COG).

Value

either a data.frame or a 'sf' objects depending on dataset type

Details

The scope is done at the scale of the municipalities

Examples

dataset = data.frame(
   id = (1:5),
   adresse = letters[1:5], 
   commune = c("32456", "36980", "37865", "76543", "34172")
)
dataset
#>   id adresse commune
#> 1  1       a   32456
#> 2  2       b   36980
#> 3  3       c   37865
#> 4  4       d   76543
#> 5  5       e   34172

select_scope(dataset, scope = "34172")
#>   id adresse commune
#> 5  5       e   34172

select_scope(dataset, scope = c("36980","34172") )
#>   id adresse commune
#> 2  2       b   36980
#> 5  5       e   34172

# scope's value is out of the dataset
select_scope(dataset, scope = "39876")  
#> [1] id      adresse commune
#> <0 rows> (or 0-length row.names)

# Two values are in the scope and one is out
select_scope(dataset, scope = c("36980", "34179", "32456")) 
#>   id adresse commune
#> 1  1       a   32456
#> 2  2       b   36980