Round numeric movement data
round_weights.Rd
round_weights()
rounds a selected numeric column in a movenet-format
movement tibble. By default, the weight column is selected.
Arguments
- data
A movenet-format movement tibble.
- unit
A positive number. The data in the selected column are rounded to the nearest multiple of this number.
unit
is additionally set as minimum possible value for the column.- column
Name of a single numeric column to round. By default this is the weight column (as specified in the loaded movement configurations).
Details
Requires that the appropriate movement config file is loaded, to correctly
identify the weight
column in data
.
The data in the selected column are modified by rounding to multiples of
unit
.
Additionally, any data points < unit
are set to unit
, so that this
becomes the minimum possible value in the column. This is to capture that any
livestock movement, no matter how small, has an inherent risk that is
conceptually closer to that of unit
, than that of no movement at all.
See also
plyr::round_any()
, which this function wraps.
Other Privacy-enhancing functions:
anonymise()
,
create_anonymisation_effect_analysis_report()
,
jitter_dates()
,
jitter_weights()
,
round_dates()
Examples
# Set-up: Save movenet environment with current configurations
movenetenv <- movenet:::movenetenv
old_config <- movenetenv$options
# Load a movement config file
load_config(system.file("configurations", "ScotEID.yml",
package = "movenet"))
#> Successfully loaded config file: C:/Users/cboga/AppData/Local/Temp/Rtmp25xhub/temp_libpath11484970381d/movenet/configurations/ScotEID.yml
# Round movement weights to multiples of 5 (and set 5 as minimum value)
moves_w_rounded_weights <- round_weights(example_movement_data, 5)
head(moves_w_rounded_weights)
#> # A tibble: 6 x 5
#> departure_cph dest_cph departure_date qty_pigs movement_reference
#> <chr> <chr> <date> <dbl> <dbl>
#> 1 95/216/1100 19/818/9098 2019-02-08 95 304781
#> 2 69/196/5890 71/939/3228 2019-08-15 165 229759
#> 3 52/577/5349 82/501/8178 2019-09-15 115 36413
#> 4 39/103/5541 13/282/1763 2019-10-26 125 488616
#> 5 41/788/6464 57/418/6011 2019-10-17 110 581785
#> 6 69/393/9398 39/947/2201 2019-10-06 70 564911
# Round movement reference numbers to multiples of 10 (and set 10 as minimum
# value)
moves_w_rounded_refs <-
round_weights(example_movement_data, 10, column = "movement_reference")
head(moves_w_rounded_refs)
#> # A tibble: 6 x 5
#> departure_cph dest_cph departure_date qty_pigs movement_reference
#> <chr> <chr> <date> <dbl> <dbl>
#> 1 95/216/1100 19/818/9098 2019-02-08 97 304780
#> 2 69/196/5890 71/939/3228 2019-08-15 167 229760
#> 3 52/577/5349 82/501/8178 2019-09-15 115 36410
#> 4 39/103/5541 13/282/1763 2019-10-26 125 488620
#> 5 41/788/6464 57/418/6011 2019-10-17 109 581780
#> 6 69/393/9398 39/947/2201 2019-10-06 72 564910
# Clean-up: Reinstate previous configurations
movenetenv$options <- old_config
rm("old_config", "movenetenv", "moves_w_rounded_weights",
"moves_w_rounded_refs")