This function extracts the identifying variables from a table by applying a schema description to it.

getIDVars(schema = NULL, input = NULL)

Arguments

schema

[character(1)]
the (validated) schema description of input.

input

[character(1)]
table to reorganise.

Value

a list per cluster with values of the identifying variables

Examples

input <- tabs2shift$clusters_nested
schema <- setCluster(id = "sublevel",
                     group = "territories", member = c(1, 1, 2),
                     left = 1, top = c(3, 8, 15)) %>%
  setIDVar(name = "territories", columns = 1, rows = c(2, 14)) %>%
  setIDVar(name = "sublevel", columns = 1, rows = c(3, 8, 15)) %>%
  setIDVar(name = "year", columns = 7) %>%
  setIDVar(name = "commodities", columns = 2) %>%
  setObsVar(name = "harvested", columns = 5) %>%
  setObsVar(name = "production", columns = 6)

validateSchema(schema = schema, input = input) %>%
   getIDVars(input = input)
#> Warning: validateSchema(): 'rows' is set for variable 'territories', but 'columns' has only one entry (column 1). 'rows' is only meaningful when the variable spans multiple columns (wide format). If you want a distinct variable, set distinct = TRUE and provide explicit rows.
#> Warning: validateSchema(): variable 'territories' has rows = c(2, 14) (length 2) but there are 3 cluster origins. The number of row values should match the number of cluster origins.
#> [[1]]
#> [[1]]$year
#> # A tibble: 4 × 1
#>   X7    
#>   <chr> 
#> 1 year 1
#> 2 year 1
#> 3 year 2
#> 4 year 2
#> 
#> [[1]]$commodities
#> # A tibble: 4 × 1
#>   X2     
#>   <chr>  
#> 1 soybean
#> 2 maize  
#> 3 soybean
#> 4 maize  
#> 
#> 
#> [[2]]
#> [[2]]$year
#> # A tibble: 4 × 1
#>   X7    
#>   <chr> 
#> 1 year 1
#> 2 year 1
#> 3 year 2
#> 4 year 2
#> 
#> [[2]]$commodities
#> # A tibble: 4 × 1
#>   X2     
#>   <chr>  
#> 1 soybean
#> 2 maize  
#> 3 soybean
#> 4 maize  
#> 
#> 
#> [[3]]
#> [[3]]$year
#> # A tibble: 4 × 1
#>   X7    
#>   <chr> 
#> 1 year 1
#> 2 year 1
#> 3 year 2
#> 4 year 2
#> 
#> [[3]]$commodities
#> # A tibble: 4 × 1
#>   X2     
#>   <chr>  
#> 1 soybean
#> 2 maize  
#> 3 soybean
#> 4 maize  
#> 
#>