This function allows to specify additional rules to filter certain rows
setFilter(
schema = NULL,
rows = NULL,
columns = NULL,
invert = FALSE,
operator = NULL
)
[schema(1)
]
In case this information is added to an
already existing schema, provide that schema here (overwrites previous
information).
[integerish(.)
]
rows that are mentioned here are kept.
[integerish(.)
]
columns that are mentioned here are
kept.
[logical(1)
]
whether or not to invert the specified
columns or rows.
[function(1)
]Logic
operators
by which the current filter should be combined with the directly preceeding
filter; hence this argument is not used in case no other filter was defined
before it.
An object of class schema
.
Other functions to describe table arrangement:
setCluster()
,
setFormat()
,
setGroups()
,
setIDVar()
,
setObsVar()
(input <- tabs2shift$messy_rows)
#> # A tibble: 16 × 7
#> X1 X2 X3 X4 X5 X6 X7
#> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
#> 1 territories period commodities other_observed harvested production empty_col
#> 2 1 - all xyz 999 999 NA
#> 3 2 - none xyz 999 999 NA
#> 4 NA NA NA NA NA NA NA
#> 5 3 - xyz xyz 999 999 NA
#> 6 4 - 5 xyz 999 999 NA
#> 7 unit 1 year 1 soybean xyz 1111 1112 NA
#> 8 unit 1 year 1 maize xyz 1121 1122 NA
#> 9 unit 1 year 2 soybean xyz 1211 1212 NA
#> 10 unit 1 year 2 maize xyz 1221 1222 NA
#> 11 5 - all NA 999 999 NA
#> 12 6 - none NA 999 999 NA
#> 13 unit 2 year 1 soybean xyz 2111 2112 NA
#> 14 unit 2 year 1 maize xyz 2121 2122 NA
#> 15 unit 2 year 2 soybean xyz 2211 2212 NA
#> 16 unit 2 year 2 maize xyz 2221 2222 NA
# select rows where there is 'unit 2' in column 1 or 'year 2' in column 2
schema <-
setFilter(rows = .find(pattern = "unit 2", col = 1)) %>%
setFilter(rows = .find(pattern = "year 2", col = 2), operator = `|`) %>%
setIDVar(name = "territories", columns = 1) %>%
setIDVar(name = "year", columns = 2) %>%
setIDVar(name = "commodities", columns = 3) %>%
setObsVar(name = "harvested", columns = 5) %>%
setObsVar(name = "production", columns = 6)
reorganise(schema = schema, input = input)
#> filling NA-values in downwards direction in column 'territories'.
#> filling NA-values in downwards direction in column 'year'.
#> filling NA-values in downwards direction in column 'commodities'.
#> # A tibble: 6 × 5
#> territories year commodities harvested production
#> <chr> <chr> <chr> <dbl> <dbl>
#> 1 unit 1 year 2 soybean 1211 1212
#> 2 unit 1 year 2 maize 1221 1222
#> 3 unit 2 year 1 soybean 2111 2112
#> 4 unit 2 year 1 maize 2121 2122
#> 5 unit 2 year 2 soybean 2211 2212
#> 6 unit 2 year 2 maize 2221 2222