This function processes a dataset to calculate the total feed intake per location, date, and responder. It then identifies days where the sum of feed intake is below a threshold, specifically less than 0.5 kg. The results are returned in a wide format with each location and responder combination as a row and dates as columns.
low_feedintake(data, days, ref_date = Sys.Date())
A data table that must include the columns: 'location', 'date', 'responder', and 'feed_intake'. The 'visit_time' must be able to be converted to IDateTime format.
An integer specifying the number of days to include in the analysis up to and including the reference date.
A Date object used as the reference date for filtering data; defaults to the current system date.
Returns a data table in wide format where each row represents a combination of location and responder, columns are dates, and values are the summed feed intake that are below the threshold of 0.5 kg. Also includes a 'sum_feedintake' column which is the total sum of feed intake across the period for each row.
This function assumes that the input data has been preprocessed to include the necessary columns. It will stop and raise an error if the 'visit_time' cannot be converted to date and time format.
# Load CSV data
data <- data.table::fread("C:/Users/Dell/Documents/projects/pptsdm_data/ppt_monitor_test_data.csv")
print(low_feedintake(data = data, days = 5))
#> location responder 06-03 06-04 06-05 06-06 06-07 sum_feedintake
#> <int> <int> <num> <num> <num> <num> <num> <num>
#> 1: 507 2315012 NA NA NA 0.029 0.003 0.03
#> 2: 502 NA 0.081 0.046 0.056 0.087 0.027 0.30
#> 3: 510 NA NA 0.048 0.208 0.014 NA 0.27
#> 4: 503 NA NA 0.212 0.022 NA NA 0.23
#> 5: 509 NA NA NA 0.010 NA 0.152 0.16
#> 6: 504 NA 0.026 NA 0.023 NA NA 0.05
#> 7: 507 NA 0.010 0.010 0.010 NA NA 0.03
#> 8: 508 NA NA NA NA NA 0.010 0.01