This function processes a dataset to calculate the number of responders per specified 'house' (a subset of the 'location' field) for each date within a specified number of days from a reference date. The data is first processed to ensure the 'date' column is in Date format, 'house' is extracted from 'location', and duplicates are removed. The output is provided in wide format with dates as rows and houses as columns.
number_location(data, house_width, days, ref_date = Sys.Date())
A data table that must include the columns: 'location', 'date', 'responder'. The function expects that 'date' can be converted into Date format.
An integer specifying the number of characters from the start of the 'location' field to define a 'house'.
An integer specifying the number of days to include in the analysis back from 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 date and each column a house. Each entry is the count of responders for that house and date.
This function depends on another function 'process data' to first ensure the data is in the correct format. It is crucial that the input data and the 'process_data' function are properly configured to handle the data correctly.
# Load CSV data
data <- data.table::fread("C:/Users/Dell/Documents/projects/pptsdm_data/ppt_monitor_test_data.csv")
print(number_location(data = data, house_width = "1", days = 5))
#> Key: <date>
#> date 5
#> <char> <int>
#> 1: 06-03 147
#> 2: 06-04 146
#> 3: 06-05 145
#> 4: 06-06 146
#> 5: 06-07 146