Turn one column of a daily table into a wide table: stations, houses or pigs in rows, days (or hours) in columns, plus the total or mean over the window.

wide_table(x, value)

Arguments

x

A table from monitor_stations(), monitor_houses(), monitor_pigs() or monitor_hours() (also as part of run_monitor()).

value

Name of the column to show, e.g. "feed_kg".

Value

A data.table: the ID columns (location, house, or location and responder), one column per day ("MM-DD", or "YYYY-MM-DD" when the window spans the same day of two years) or per hour, and total for counts, kg and time, mean otherwise.

Examples

mon <- run_monitor(tidypptsda::nedap, verbose = 0)
wide_table(mon$stations, "n_visits")
#> Key: <location>
#>    location 05-19 05-20 05-21 05-22 05-23 05-24 05-25 total
#>      <char> <int> <int> <int> <int> <int> <int> <int> <num>
#> 1:      101   192   201   228   214   234   154   204  1427
#> 2:      102   163   167   216   238   158   118   162  1222
wide_table(mon$pigs, "feed_kg")
#> Key: <location, responder>
#>     location responder 05-19 05-20 05-21 05-22 05-23 05-24 05-25  total
#>       <char>    <char> <num> <num> <num> <num> <num> <num> <num>  <num>
#>  1:      101     13913 4.175 2.858 4.514 2.832 4.068 2.665 3.717 24.829
#>  2:      101     13918 3.655 2.685 2.619 2.467 3.792 3.107 2.231 20.556
#>  3:      101     13954 3.505 3.681 1.168 1.664 2.796 3.738 3.015 19.567
#>  4:      101     13996 3.386 4.986 4.590 3.892 4.558 4.698 3.215 29.325
#>  5:      101     14962 4.124 4.278 3.635 4.764 4.075 3.402 3.290 27.568
#>  6:      101     15006 4.894 4.577 4.562 4.497 3.837 3.875 3.923 30.165
#>  7:      101     15034 3.294 3.850 3.612 2.264 2.937 1.878 3.135 20.970
#>  8:      101     15073 3.680 3.995 3.549 3.873 3.648 3.149 4.358 26.252
#>  9:      101     15088 3.458 2.650 2.672 2.994 3.343 2.811 2.815 20.743
#> 10:      101     15497 3.624 4.131 3.971 3.250 3.344 3.148 2.876 24.344
#> 11:      101     15927 3.739 2.937 2.867 3.581 3.118 3.250 2.305 21.797
#> 12:      101     15961 4.846 3.762 3.983 4.999 4.599 4.284 4.502 30.975
#> 13:      101     15983 4.364 4.832 4.750 3.502 2.994 4.385 2.561 27.388
#> 14:      102     13935 3.783 4.279 2.207 3.940 2.575 3.987 3.225 23.996
#> 15:      102     14260 4.488 3.790 2.989 3.132 4.760 4.014 3.035 26.208
#> 16:      102     14730 3.844 3.766 3.379 4.071 3.153 3.602 3.928 25.743
#> 17:      102     14751 2.636 3.173 2.236 2.988 2.839 3.189 1.835 18.896
#> 18:      102     14759 4.083 3.576 3.211 4.122 3.570 3.465 3.282 25.309
#> 19:      102     14903 4.611 3.506 3.795 3.617 4.132 3.535 3.128 26.324
#> 20:      102     14913 4.717 3.582 3.574 4.514 3.040 5.207 3.296 27.930
#> 21:      102     14915 3.571 3.521 2.333 3.225 3.468 2.991 1.609 20.718
#> 22:      102     14937 4.110 5.785 3.734 4.053 4.069 3.896 2.956 28.603
#> 23:      102     14969 5.269 3.881 4.175 3.288 4.418 2.935 3.631 27.597
#> 24:      102     15404 3.659 3.046 3.549 2.379 2.446 4.178 1.751 21.008
#> 25:      102     15496 3.596 4.522 4.474 4.767 3.119 4.265 4.458 29.201
#> 26:      102     15604 3.382 4.139 2.094 3.528 2.636 3.790 2.058 21.627
#> 27:      102     15626 2.869 2.849 2.721 3.019 2.534 2.209 2.590 18.791
#> 28:      102     15649 4.134 2.939 3.170 3.191 3.663 3.869 1.982 22.948
#>     location responder 05-19 05-20 05-21 05-22 05-23 05-24 05-25  total
#>       <char>    <char> <num> <num> <num> <num> <num> <num> <num>  <num>
wide_table(mon$hours, "feed_kg")
#> Key: <location>
#>    location    00    01    02    03    04    05    06    07    08    09    10
#>      <char> <num> <num> <num> <num> <num> <num> <num> <num> <num> <num> <num>
#> 1:      101 0.541 1.088 1.805 1.082 0.479 1.469 2.791 2.766 2.682 1.829 3.184
#> 2:      102 3.055 0.382 1.963 1.714 0.010 1.761 2.406 2.556 2.053 2.478 2.866
#>       11    12    13    14    15    16    17    18    19    20    21    22
#>    <num> <num> <num> <num> <num> <num> <num> <num> <num> <num> <num> <num>
#> 1: 2.748 2.692 0.996 2.174 2.642 1.908 2.647 2.298 2.239 1.970     0     0
#> 2: 2.837 1.200 0.086 2.859 2.475 2.435 2.452 2.853 1.996 2.347     0     0
#>       23  total
#>    <num>  <num>
#> 1:     0 42.030
#> 2:     0 42.784
mon <- run_monitor(tidypptsda::nedap, verbose = 0)
wide_table(mon$stations, "n_visits")
#> Key: <location>
#>    location 05-19 05-20 05-21 05-22 05-23 05-24 05-25 total
#>      <char> <int> <int> <int> <int> <int> <int> <int> <num>
#> 1:      101   192   201   228   214   234   154   204  1427
#> 2:      102   163   167   216   238   158   118   162  1222
wide_table(mon$pigs, "feed_kg")
#> Key: <location, responder>
#>     location responder 05-19 05-20 05-21 05-22 05-23 05-24 05-25  total
#>       <char>    <char> <num> <num> <num> <num> <num> <num> <num>  <num>
#>  1:      101     13913 4.175 2.858 4.514 2.832 4.068 2.665 3.717 24.829
#>  2:      101     13918 3.655 2.685 2.619 2.467 3.792 3.107 2.231 20.556
#>  3:      101     13954 3.505 3.681 1.168 1.664 2.796 3.738 3.015 19.567
#>  4:      101     13996 3.386 4.986 4.590 3.892 4.558 4.698 3.215 29.325
#>  5:      101     14962 4.124 4.278 3.635 4.764 4.075 3.402 3.290 27.568
#>  6:      101     15006 4.894 4.577 4.562 4.497 3.837 3.875 3.923 30.165
#>  7:      101     15034 3.294 3.850 3.612 2.264 2.937 1.878 3.135 20.970
#>  8:      101     15073 3.680 3.995 3.549 3.873 3.648 3.149 4.358 26.252
#>  9:      101     15088 3.458 2.650 2.672 2.994 3.343 2.811 2.815 20.743
#> 10:      101     15497 3.624 4.131 3.971 3.250 3.344 3.148 2.876 24.344
#> 11:      101     15927 3.739 2.937 2.867 3.581 3.118 3.250 2.305 21.797
#> 12:      101     15961 4.846 3.762 3.983 4.999 4.599 4.284 4.502 30.975
#> 13:      101     15983 4.364 4.832 4.750 3.502 2.994 4.385 2.561 27.388
#> 14:      102     13935 3.783 4.279 2.207 3.940 2.575 3.987 3.225 23.996
#> 15:      102     14260 4.488 3.790 2.989 3.132 4.760 4.014 3.035 26.208
#> 16:      102     14730 3.844 3.766 3.379 4.071 3.153 3.602 3.928 25.743
#> 17:      102     14751 2.636 3.173 2.236 2.988 2.839 3.189 1.835 18.896
#> 18:      102     14759 4.083 3.576 3.211 4.122 3.570 3.465 3.282 25.309
#> 19:      102     14903 4.611 3.506 3.795 3.617 4.132 3.535 3.128 26.324
#> 20:      102     14913 4.717 3.582 3.574 4.514 3.040 5.207 3.296 27.930
#> 21:      102     14915 3.571 3.521 2.333 3.225 3.468 2.991 1.609 20.718
#> 22:      102     14937 4.110 5.785 3.734 4.053 4.069 3.896 2.956 28.603
#> 23:      102     14969 5.269 3.881 4.175 3.288 4.418 2.935 3.631 27.597
#> 24:      102     15404 3.659 3.046 3.549 2.379 2.446 4.178 1.751 21.008
#> 25:      102     15496 3.596 4.522 4.474 4.767 3.119 4.265 4.458 29.201
#> 26:      102     15604 3.382 4.139 2.094 3.528 2.636 3.790 2.058 21.627
#> 27:      102     15626 2.869 2.849 2.721 3.019 2.534 2.209 2.590 18.791
#> 28:      102     15649 4.134 2.939 3.170 3.191 3.663 3.869 1.982 22.948
#>     location responder 05-19 05-20 05-21 05-22 05-23 05-24 05-25  total
#>       <char>    <char> <num> <num> <num> <num> <num> <num> <num>  <num>