Function that is used internally to change the data back to their original
format after conducting an analysis, it being either binning
(bin()) or using the Kalman filter
(kalman_filter()). The finalization consists of
renaming the columns to the user-defined column names instead of the package-
required ones and deleting the grouping variable if it was not originally
present in the data.
Arguments
- data
Dataframe that contains information on location (x- and y-coordinates) and the time at which the measurement was taken. It is assumed that this information is contained within the columns
"x","y", and"time"respectively.- cols
Named vector or named list containing the mapping of the original column names to the internal ones used within the package. Defaults to
NULL, therefore assuming the structure explained indata.- .by
String denoting whether the moving window should be taken with respect to a given grouping variable. Defaults to
NULL.
Examples
# Generate data for illustration purposes
#
# Note that for this to work, I need to define the package-required column
# names
data <- data.frame(
x = rnorm(100),
y = rnorm(100),
time = rep(1:50, times = 2) / 10,
id = rep(1:2, each = 50)
)
# Prepare the data for analysis
finalize(
data,
cols = c(
"time" = "seconds",
"x" = "X",
"y" = "Y"
),
.by = "tag"
)
#> seconds X Y
#> 1 0.1 0.23609585 0.893165020
#> 2 0.2 0.62895342 -0.376555496
#> 3 0.3 0.41792568 0.605884808
#> 4 0.4 1.97675848 -0.004874726
#> 5 0.5 -0.50628630 -0.520796373
#> 6 0.6 -1.10996885 -0.639018598
#> 7 0.7 -0.94870572 -0.635894137
#> 8 0.8 0.47684376 0.106586975
#> 9 0.9 -0.79520156 1.176914248
#> 10 1.0 0.23432692 0.447391153
#> 11 1.1 -1.22245110 2.272954766
#> 12 1.2 -2.45364735 0.136058206
#> 13 1.3 -1.48926081 -1.999039133
#> 14 1.4 -0.43214773 -0.420500870
#> 15 1.5 -0.94255401 -0.378407395
#> 16 1.6 -0.12145080 1.220774789
#> 17 1.7 1.33644680 -1.541030292
#> 18 1.8 -0.86035618 -0.310310122
#> 19 1.9 0.66653782 -0.020108184
#> 20 2.0 -1.42153475 -2.390200336
#> 21 2.1 1.17005617 0.889865359
#> 22 2.2 -1.40471454 -1.482813325
#> 23 2.3 1.10170810 0.445750348
#> 24 2.4 0.69798626 1.369775856
#> 25 2.5 -0.86434980 -0.020110027
#> 26 2.6 -1.09147035 -0.109217587
#> 27 2.7 -0.03705146 0.264661745
#> 28 2.8 0.81005379 0.303848264
#> 29 2.9 -0.49935541 -0.183388483
#> 30 3.0 0.94803159 0.559649672
#> 31 3.1 -0.17424596 -0.186553842
#> 32 3.2 -1.10623595 -0.812275372
#> 33 3.3 -0.94598501 -1.640581672
#> 34 3.4 0.28908959 0.507922478
#> 35 3.5 0.87691314 1.754336961
#> 36 3.6 -1.14890394 0.592400202
#> 37 3.7 -1.13761276 1.016713288
#> 38 3.8 -1.43724674 0.121620586
#> 39 3.9 -0.49414348 -1.078067265
#> 40 4.0 0.84080181 -1.143565720
#> 41 4.1 0.79153412 -0.529643677
#> 42 4.2 -0.16884895 -0.681273156
#> 43 4.3 0.61272210 -0.202447559
#> 44 4.4 -0.77115892 1.684495721
#> 45 4.5 0.88862899 -1.033773237
#> 46 4.6 0.01321448 -0.155976673
#> 47 4.7 0.22533951 -0.046400637
#> 48 4.8 -0.72991521 -0.953628727
#> 49 4.9 -1.22248707 0.416260798
#> 50 5.0 0.40680517 0.114029609
#> 51 0.1 -0.75101222 0.063918753
#> 52 0.2 -0.16211654 -0.919332238
#> 53 0.3 0.35201013 0.901335290
#> 54 0.4 -0.28905830 -0.797728297
#> 55 0.5 0.10466223 0.668221204
#> 56 0.6 0.72018653 0.155214296
#> 57 0.7 -0.61104608 0.128688092
#> 58 0.8 -1.10691407 -1.533065453
#> 59 0.9 0.53480333 0.202360673
#> 60 1.0 0.73606797 -0.717538653
#> 61 1.1 -1.22250157 0.361694761
#> 62 1.2 1.02141531 1.399004294
#> 63 1.3 0.46516516 0.372698962
#> 64 1.4 0.79047270 -1.565644294
#> 65 1.5 -0.13026480 -0.051694539
#> 66 1.6 -0.93028533 0.514082103
#> 67 1.7 -0.36485100 0.549899523
#> 68 1.8 0.15387249 0.867816913
#> 69 1.9 0.41315482 0.684360081
#> 70 2.0 2.48082336 -0.162679977
#> 71 2.1 -2.17995674 -1.784364724
#> 72 2.2 0.42087458 -1.037145566
#> 73 2.3 -0.35752832 0.830147723
#> 74 2.4 -0.64686151 0.607346945
#> 75 2.5 -0.05014180 -0.122186361
#> 76 2.6 0.41694285 0.933125139
#> 77 2.7 -0.63258754 -0.961276680
#> 78 2.8 1.15014667 0.255081707
#> 79 2.9 -0.23547591 -0.545401573
#> 80 3.0 -1.64310739 0.930360736
#> 81 3.1 -1.50338215 -0.537650558
#> 82 3.2 -2.05058485 -0.452426068
#> 83 3.3 -0.75319823 -0.439290972
#> 84 3.4 -0.13414196 -0.616223111
#> 85 3.5 1.00578285 0.441634552
#> 86 3.6 2.16718680 0.482597453
#> 87 3.7 2.32255654 0.542144383
#> 88 3.8 -1.02042339 -2.290784653
#> 89 3.9 0.04881444 0.310351853
#> 90 4.0 -0.77188863 1.404078979
#> 91 4.1 -0.78523507 1.377117639
#> 92 4.2 -0.72660303 1.060395652
#> 93 4.3 0.68187803 0.632172891
#> 94 4.4 -0.22984329 1.084928035
#> 95 4.5 -1.51060172 1.356459439
#> 96 4.6 -0.58372769 0.362424040
#> 97 4.7 -2.02291845 2.169344465
#> 98 4.8 0.40350468 0.139130512
#> 99 4.9 0.55001555 1.376326526
#> 100 5.0 0.02835712 -0.491449988