This function matches food names to a standard list of food items and returns a data frame with the matched food names and codes. The function can use an internal food list or a user-provided food list to perform the matching. The function also provides diagnostics on the number of rows with no matches found and the list of foods with no matches found.
Usage
match_food_names_v2(
data,
country,
survey,
food_name_col,
food_code_col,
matches_csv = NULL,
overwrite = FALSE
)
Arguments
- data
A data frame containing the food names and codes to be matched.
- country
A character string specifying the country for which the food items should be matched.
- survey
A character string specifying the survey for which the food items should be matched.
- food_name_col
A character string specifying the name of the column in
data
containing the food names.- food_code_col
A character string specifying the name of the column in
data
containing the food codes.- matches_csv
A character string specifying the path to a user-provided CSV file containing the food list to be used for matching. If
NULL
, the function uses an internal food list.- overwrite
A logical value indicating whether to overwrite the original food name and code columns in
data
with the matched food names and codes. IfTRUE
, the original columns are overwritten. IfFALSE
, new columns are created for the matched food names and codes.
Examples
if (FALSE) { # \dontrun{
# Load the MWI data
data("mwi_data", package = "hcesNutR")
# Match the food names to the standard list of food items
matched_data <- match_food_names_v2(data = mwi_data,
country = "MWI",
survey = "IHS5",
food_name_col = "food_item_name",
food_code_col = "food_item_code")
} # }