The hour_stat
function computes hourly statistics for given data,
including the number of visits, total feed time, and total feed intake,
grouped by location and hour. This function is designed for processing
time-series data related to feeding or visit behaviors.
hour_stat(data, target_date = Sys.Date() - 1)
data.table, required.
The input data table which must contain the following columns:
visit_time
(POSIXct), location
(character), duration
(numeric, in minutes),
and feed_intake
(numeric, in grams).
Date, optional.
The specific date for which the data should be filtered. Defaults to 35 days prior
to today (using Sys.Date() - 35
).
A list of data.tables containing hourly statistics:
visit_n
: Number of visits per location per hour.
feed_time
: Total feed time in hours per location per hour.
feed_intake
: Total feed intake in kilograms per location per hour.
The function requires that the data
table contains specific columns named
visit_time
, location
, duration
, and feed_intake
. The visit_time
should
be in POSIXct format for accurate processing.
# Load CSV data
data <- data.table::fread("C:/Users/Dell/Documents/projects/pptsdm_data/ppt_monitor_test_data.csv")
print(hour_stat(data = data))
#> $visit_n
#> Key: <location>
#> location 0 1 2 3 4 5 6 7 8 9 10
#> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int>
#> 1: 501 3 5 4 4 4 3 4 9 5 5 8
#> 2: 502 4 1 3 4 1 2 4 4 4 4 4
#> 3: 503 2 7 4 3 1 3 3 3 4 2 7
#> 4: 504 4 4 1 5 1 2 3 3 3 5 4
#> 5: 505 5 9 4 3 2 4 4 2 4 5 3
#> 6: 506 3 4 2 3 1 1 3 2 4 2 4
#> 7: 507 4 1 5 3 1 2 3 5 4 3 3
#> 8: 508 5 3 1 4 3 3 3 3 4 2 3
#> 9: 509 3 5 5 1 3 2 2 4 6 4 3
#> 10: 510 3 NA 3 2 3 2 1 3 2 3 3
#> 11 12 13 14 15 16 17 18 19 20 21 22
#> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int>
#> 1: 4 4 6 4 9 10 6 6 4 5 3 2
#> 2: 3 3 4 5 5 5 4 5 5 4 1 5
#> 3: 5 4 4 4 4 5 7 5 4 4 1 6
#> 4: 5 3 5 3 9 4 5 3 4 2 1 3
#> 5: 8 7 6 6 6 7 8 6 4 5 4 1
#> 6: 6 2 4 6 3 5 4 3 3 4 5 5
#> 7: 6 5 7 3 4 5 5 4 4 NA NA 5
#> 8: 5 4 3 3 6 5 4 3 3 4 4 3
#> 9: 8 5 5 10 8 12 4 7 3 7 9 3
#> 10: 3 4 2 3 7 5 3 3 2 3 4 2
#> 23
#> <int>
#> 1: 4
#> 2: NA
#> 3: 4
#> 4: 3
#> 5: 2
#> 6: 1
#> 7: 1
#> 8: 2
#> 9: 6
#> 10: 4
#>
#> $feed_time
#> Key: <location>
#> location 0 1 2 3 4 5 6 7 8 9 10
#> <int> <num> <num> <num> <num> <num> <num> <num> <num> <num> <num> <num>
#> 1: 501 9.57 33.95 48.88 59.77 34.53 36.38 50.50 41.57 52.70 55.47 48.17
#> 2: 502 36.35 12.25 37.57 53.27 11.37 18.67 36.13 62.23 42.80 49.67 48.58
#> 3: 503 18.97 39.23 40.38 21.13 6.62 29.62 50.40 41.62 71.25 23.22 50.48
#> 4: 504 33.45 56.98 7.00 68.78 12.65 25.65 34.40 28.45 36.30 60.68 56.87
#> 5: 505 30.82 34.20 17.30 25.02 18.45 46.52 52.07 21.17 45.72 74.60 44.17
#> 6: 506 66.65 50.72 16.48 31.30 8.08 18.82 58.05 47.10 57.83 46.55 54.50
#> 7: 507 41.03 13.78 51.38 44.87 20.98 28.35 39.22 56.10 45.87 49.72 40.87
#> 8: 508 48.92 21.32 6.23 29.35 47.57 70.88 40.70 41.55 50.60 45.07 34.77
#> 9: 509 31.62 78.10 18.28 13.12 26.80 14.27 27.50 66.20 48.47 56.48 53.45
#> 10: 510 20.72 NA 58.38 30.07 59.98 47.35 12.75 55.05 42.08 57.80 54.02
#> 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: 60.68 48.07 48.53 51.03 52.95 43.55 64.73 60.97 55.23 45.68 49.97 21.82
#> 2: 45.80 25.98 51.55 58.68 61.32 56.58 64.05 47.82 65.83 41.63 6.27 43.73
#> 3: 40.33 21.33 50.57 64.28 55.67 48.55 54.83 62.55 41.50 53.48 5.27 45.27
#> 4: 60.58 41.45 68.10 47.85 44.65 60.88 56.72 51.77 46.52 19.98 4.45 23.38
#> 5: 40.10 48.08 32.12 52.98 57.20 44.18 57.08 67.37 56.15 63.82 33.68 1.47
#> 6: 73.53 50.00 50.40 76.15 42.93 58.73 62.28 56.82 58.42 50.52 42.28 27.53
#> 7: 53.45 39.77 44.08 61.90 59.02 59.58 51.63 63.30 54.67 NA NA 48.00
#> 8: 71.40 58.88 55.20 19.07 56.52 55.00 74.32 52.77 45.13 30.10 28.83 25.30
#> 9: 60.33 32.93 46.25 58.73 50.37 63.55 49.32 70.85 42.20 34.58 34.50 7.27
#> 10: 53.03 79.35 35.85 58.28 66.23 54.53 67.92 48.00 25.55 32.32 40.65 27.12
#> 23
#> <num>
#> 1: 37.85
#> 2: NA
#> 3: 15.00
#> 4: 41.63
#> 5: 15.62
#> 6: 0.83
#> 7: 9.15
#> 8: 21.32
#> 9: 15.37
#> 10: 36.28
#>
#> $feed_intake
#> Key: <location>
#> location 0 1 2 3 4 5 6 7 8 9 10
#> <int> <num> <num> <num> <num> <num> <num> <num> <num> <num> <num> <num>
#> 1: 501 0.40 1.10 2.05 2.18 1.90 1.41 2.23 2.26 1.85 2.29 2.13
#> 2: 502 1.73 0.81 1.80 2.45 0.53 1.00 1.76 3.04 1.86 2.58 2.39
#> 3: 503 0.84 1.90 2.20 1.07 0.31 1.37 2.44 2.53 3.84 1.01 2.41
#> 4: 504 1.32 2.61 0.35 3.07 0.72 1.52 1.75 1.34 1.66 2.63 2.85
#> 5: 505 1.29 1.16 0.56 1.21 0.89 2.02 2.39 0.97 2.24 2.87 2.32
#> 6: 506 2.60 2.15 0.72 1.43 0.47 0.66 2.44 2.02 2.72 2.09 2.13
#> 7: 507 1.73 0.60 2.06 2.28 0.82 1.35 1.88 2.61 1.94 2.10 1.48
#> 8: 508 1.81 0.80 0.19 1.09 2.23 3.16 1.59 1.97 1.99 1.92 1.21
#> 9: 509 1.55 4.37 1.29 0.80 1.32 0.45 1.22 3.39 2.64 2.89 2.88
#> 10: 510 0.82 NA 2.50 1.27 2.87 1.63 0.54 2.55 1.76 2.52 2.54
#> 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.28 1.94 2.48 1.78 2.20 1.51 2.42 2.71 2.80 2.26 2.27 0.80
#> 2: 2.19 1.50 2.63 2.89 2.98 2.89 3.69 2.80 3.33 2.38 0.36 2.50
#> 3: 1.92 1.13 2.52 3.35 3.10 2.25 3.01 3.18 1.96 2.48 0.21 2.52
#> 4: 2.91 2.38 3.44 2.35 2.11 3.10 2.93 2.80 2.17 0.88 0.28 1.02
#> 5: 1.47 2.22 1.67 2.65 2.06 2.15 1.64 3.80 3.38 3.34 1.44 0.08
#> 6: 3.11 1.73 2.24 3.74 1.47 1.79 3.10 2.63 3.00 2.27 1.91 1.30
#> 7: 2.43 2.05 1.60 2.75 2.82 2.41 2.75 3.26 3.07 NA NA 2.02
#> 8: 3.38 2.73 2.04 0.87 2.19 2.23 3.39 2.64 2.18 1.21 1.39 0.84
#> 9: 3.29 1.44 1.73 2.42 2.29 2.67 3.44 3.86 1.83 1.59 1.53 0.40
#> 10: 2.24 3.77 1.20 2.77 2.19 2.42 3.39 2.52 1.06 1.61 1.62 0.91
#> 23
#> <num>
#> 1: 1.07
#> 2: NA
#> 3: 0.90
#> 4: 1.79
#> 5: 0.64
#> 6: 0.02
#> 7: 0.56
#> 8: 0.92
#> 9: 0.81
#> 10: 1.30
#>