R/house_weight.R
house_weight.Rd
This function processes a dataset to extract weights by specified house (part of location), calculates mean weights per house over a given number of days from a reference date, and returns the data in a wide format with dates as rows and houses as columns.
house_weight(data, house_width = "1", days, ref_date = Sys.Date())
A data frame that must include the columns: "location", "date", and "weight".
A string indicating the number of characters to use from the 'location' column to create the 'house' identifier. Defaults to "1".
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 frame in wide format where each column represents a house and each row represents a date within the specified range. Values are mean weights (in kilograms, rounded to two decimal places) for each house-date combination.
If 'data' does not contain the necessary columns, the function will stop with an error message. It is crucial to ensure that the 'location' and 'date' columns are formatted correctly.