Skip to contents

This function categorizes individuals' diet quality based on their total fruit and vegetable consumption.

Usage

determine_gooddiet(totalFV)

Arguments

totalFV

numeric A numeric vector representing the average times per day fruits and vegetables were consumed in a year.

Value

integer A categorical indicating the diet quality:

  • 1: Good diet (totalFV >= 5)

  • 2: Poor diet (totalFV < 5)

  • haven::tagged_na("a"): Valid skip

  • haven::tagged_na("b"): Missing

Details

This function categorizes diet quality based on the widely recognized "5-a-day" recommendation for fruit and vegetable intake.

     **Missing Data Codes:**
     - Propagates tagged NAs from the input `totalFV`.

Examples

# Scalar usage: Single respondent
# Example 1: Categorize a totalFV value of 3 as poor diet
determine_gooddiet(3)
#> [1] 2
# Output: 2

# Example 2: Categorize a totalFV value of 7 as good diet
determine_gooddiet(7)
#> [1] 1
# Output: 1

# Multiple respondents
determine_gooddiet(c(3, 7, 5))
#> [1] 2 1 1
# Returns: c(2, 1, 1)

# Database usage: Applied to survey datasets
library(dplyr)
# dataset %>%
#   mutate(diet_quality = determine_gooddiet(total_fv))