R/starchy_fill.R

Defines functions starchy_fill

Documented in starchy_fill

#' Starchy vegetables serves addition
#'
#' Adds minimum and maximum serves of starchy vegetables.
#' @param df Dataframe.
#' @param starchy_name Starchy vegetables food group name. Default 'Starchy vegetables'.
#' @param serve_identifier Serve column identifier. Default 'serve'.
#' @param max_identifier Max column identifier. Default 'max'.
#' @return Food group dataframe with starchy vegetable minimum and maximum serves columns added.
#' @export
starchy_fill <- function(df,starchy_name, serve_identifier, max_identifier){
  row = which(df['food_group'] == starchy_name)
  for(column in which(grepl(serve_identifier,colnames(df))&grepl(max_identifier,colnames(df)))){
    if((is.numeric(df[row,column]) && df[row,column] == 0)||(is.na(df[row,column]))){
      df[row,column] <- 100
    }
  }
  return(df)
}

Try the DIETCOST package in your browser

Any scripts or data that you put into this service are public.

DIETCOST documentation built on June 8, 2025, 1:51 p.m.