setzero: Set values to '0' for potato and sweetpotato data.

View source: R/setzero.R

setzeroR Documentation

Set values to 0 for potato and sweetpotato data.

Description

Set values to 0 for variables at harvest.

Usage

setzero(dfr, crop = c("auto", "pt", "sp", "uk"), checknames = FALSE)

Arguments

dfr

The name of the data frame.

crop

"auto" for autodetection or "pt" for potato, "sp" for sweetpotato and "uk" for unknown.

checknames

Logical indicating if column names should be checked, default FALSE.

Details

This function sets values to 0 for all variables at harvest according to some rules.

For potato, variables (nph, nmtp, nnomtp, mtwp, and nomtwp) which are NA according to the following rules:

  • If npe > 0 and nph == 0, then all variables are set to 0.

  • If nmtp == 0, then mtwp is set to 0.

  • If mtwp == 0, then nmtp is set to 0.

  • If nnomtp == 0, then nomtwp is set to 0.

  • If nomtwp == 0, then nnomtp is set to 0.

For sweetpotato, variables (noph, nopr, vw, nocr, nonc, crw, and ncrw) which are NA according to the following rules:

  • If nope > 0 and noph == 0, then all variables are set to 0.

  • If all variables are 0, then noph is set to 0.

  • If nopr == 0, then all variables with exception of vw are set to 0.

  • If all variables with exception of vw are 0, then nopr is set to 0.

  • If nocr == 0, then crw is set to 0.

  • If crw == 0, then nocr is set to 0.

  • If nonc == 0, then ncrw is set to 0.

  • If ncrw == 0, then nonc is set to 0.

Value

It returns a data frame and a list of warnings with all the rows that have been modified.

Author(s)

Raul Eyzaguirre

Examples

dfr <- data.frame(nph = c(NA,  0,  3,  3,  3, 3, 3),
                  mtwp  = c(NA, NA, NA, NA,  8, 2, 0),
                  nomtwp = c(NA, NA, NA,  2, NA, 2, 4),
                  nmtp = c(NA, NA, NA,  0,  6, 2, 0),
                  nnomtp = c(NA, NA, NA,  4,  0, 3, 5))
setzero(dfr)
dfr <- data.frame(noph = c(NA,  0,  3,  3,  3, 3, 3),
                  nopr = c(NA,  0,  0,  2,  3, 3, 3),
                  vw   = c(NA, NA,  3,  2,  3, 3, 6),
                  crw  = c(NA, NA, NA, NA,  8, 2, 0),
                  ncrw = c(NA, NA, NA,  2, NA, 2, 4),
                  nocr = c(NA, NA, NA,  0,  6, 2, 0),
                  nonc = c(NA, NA, NA,  4,  0, 3, 5))
setzero(dfr)

reyzaguirre/st4gi documentation built on July 5, 2025, 6:38 a.m.