This function performs various checks and transformations on a provided data frame or data table. It checks for necessary columns, correct data types, and performs various operations like filtering, joining, and calculating sequences.
process_data(data)
A data frame or data table that must contain specific columns with specific data types. Required columns are: "animal_number", "lifenumber", "responder", "location", "visit_time", "duration", "state", "weight", "feed_intake".
Returns a modified data table with computed sequence features and potentially other transformations. The function ensures that columns are of the correct type and that data integrity is maintained.
This function will stop execution and produce an error if the input data does not meet the expected requirements, such as missing columns or incorrect data types.
# Load CSV data
data <- data.table::fread("C:/Users/Dell/Documents/projects/pptsdm_data/ppt_monitor_test_data.csv")
processed_data <- process_data(data = data)
head(processed_data)
#> responder location date seq_days seq_in_day seq_in_location
#> <char> <char> <IDat> <int> <int> <int>
#> 1: 2311763 503 2024-05-28 1 1 10
#> 2: 2311763 503 2024-05-28 1 2 35
#> 3: 2311763 503 2024-05-28 1 3 43
#> 4: 2311763 503 2024-05-28 1 4 45
#> 5: 2311763 503 2024-05-28 1 5 50
#> 6: 2311763 503 2024-05-28 1 6 52
#> feed_intake weight
#> <num> <num>
#> 1: 724 71000
#> 2: 12 70500
#> 3: 10 70000
#> 4: 0 70000
#> 5: 0 70000
#> 6: 1447 70500