Daily fruit and vegetable consumption in a year - cycles 1-2
Source:R/diet.R
find_totalFV_cycles1and2.RdThis function calculates the daily fruit and vegetable consumption in a year for respondent in the Canadian Health Measures Survey (CHMS) cycles 1-2. It takes seven parameters, each representing the number of times per year a specific fruit or vegetable item was consumed. The function then sums up the consumption frequencies of all these items and divides the total by 365 to obtain the average daily consumption of fruits and vegetables in a year.
Arguments
- WSDD14Y
numeric A numeric vector representing the number of times per year fruit juice was consumed.
- GFVD17Y
numeric A numeric vector representing the number of times per year fruit (excluding juice) was consumed.
- GFVD18Y
numeric A numeric vector representing the number of times per year tomato or tomato sauce was consumed.
- GFVD19Y
numeric A numeric vector representing the number of times per year lettuce or green leafy salad was consumed.
- GFVD20Y
numeric A numeric vector representing the number of times per year spinach, mustard greens, and cabbage were consumed.
- GFVD22Y
numeric A numeric vector representing the number of times per year potatoes were consumed.
- GFVD23Y
numeric A numeric vector representing the number of times per year other vegetables were consumed.
Value
numeric The average times per day fruits and vegetables were consumed in a year. If inputs are invalid or out of bounds, the function returns a tagged NA.
Details
The function calculates the total consumption of fruits and vegetables in a year by summing up the consumption frequencies of all the input items. It then divides the total by 365 to obtain the average daily consumption of fruits and vegetables in a year.
See also
find_totalFV_cycles3to6() for cycles 3-6 fruit and vegetable consumption, determine_gooddiet() for overall diet quality
Examples
# Scalar usage: Single respondent
# Example: Calculate average daily fruit and vegetable consumption for a cycle 1-2 respondent.
find_totalFV_cycles1and2(
WSDD14Y = 50, GFVD17Y = 150, GFVD18Y = 200, GFVD19Y = 100, GFVD20Y = 80,
GFVD22Y = 120, GFVD23Y = 90
)
#> [1] 2.164384
# Output: 2.164384
# Example: Respondent has non-response values for all inputs.
result <- find_totalFV_cycles1and2(
WSDD14Y = 9998, GFVD17Y = 9998, GFVD18Y = 9998, GFVD19Y = 9998, GFVD20Y = 9998,
GFVD22Y = 9998, GFVD23Y = 9998
)
result # Shows: NA
#> [1] NA
haven::is_tagged_na(result, "b") # Shows: TRUE (confirms it's tagged NA(b))
#> [1] TRUE
format(result, tag = TRUE) # Shows: "NA(b)" (displays the tag)
#> [1] "NA"
# Multiple respondents
find_totalFV_cycles1and2(
WSDD14Y = c(50, 60), GFVD17Y = c(150, 160), GFVD18Y = c(200, 210), GFVD19Y = c(100, 110),
GFVD20Y = c(80, 90), GFVD22Y = c(120, 130), GFVD23Y = c(90, 100)
)
#> [1] 2.164384 2.356164
# Returns: c(2.164384, 2.356164)