setna: Set values to 'NA' for potato and sweetpotato data.

View source: R/setna.R

setnaR Documentation

Set values to NA for potato and sweetpotato data.

Description

Detect impossible values for potato and sweetpotato data and set them to missing value (NA) according to some rules.

Usage

setna(dfr, f = 10, crop = c("auto", "pt", "sp"))

Arguments

dfr

The name of the data frame.

f

Factor for extreme values detection. See details.

crop

"auto" for autodetection or "pt" for potato and "sp" for sweetpotato.

Details

The data frame must use the labels (lower or upper case) listed in functions ptont() and spont().

Values are set to NA with the following rules:

  • All values out of the variable scale are set to NA.

  • Extreme low and high values are detected using the interquartile range. The rule is to detect any value out of the interval [Q_1 - f \times (m/3 + IQR); Q_3 + f \times (m/3 + IQR)] where m is the mean. By default f = 10 and if less than 10 a warning is shown. Values out of this range are set to NA.

  • If the number of plants established is 0 and there is some data for any variable, then the number of plants established is set to NA.

  • If the number of plants established is 0 and there is no data but some variables that are 0, then all those variables are set to NA.

  • If the number of plants harvested is 0 and there is some data for any non-pre-harvest variable, then the number of plants harvested is set to NA.

  • If the number of plants with roots or tubers is 0 and there is some data for any variable evaluated with roots or tubers, then the number of plants with roots or tubers is set to NA.

  • If the number of plants with roots or tubers is > 0 and all variables at harvest with roots are 0, then the non-commercial yields are set to NA.

  • If the number of commercial roots or tubers is 0 and the commercial root or tuber weight is > 0, then the number of commercial roots or tubers is set to NA.

  • If the number of commercial roots or tubers is > 0 and the commercial root or tuber weight is 0, then the commercial root or tuber weight is set to NA.

  • If the number of non-commercial roots or tubers is 0 and the non-commercial root or tuber weight is > 0, then the number of commercial roots or tubers is set to NA.

  • If the number of non-commercial roots or tubers is > 0 and the non-commercial root or tuber weight is 0, then the non-commercial root or tuber weight is set to NA.

Value

It returns the data frame with all impossible values set to NA and a list of warnings with all the rows that have been modified.

Author(s)

Raul Eyzaguirre.

Examples

dfr <- data.frame(mtwp = c(2.2, 5.0, 3.6, 12, 1600, -4, 0),
                  dm = c(21, 23, 105, 24, -3, 30, NA),
                  nmtp = c(1.3, 10, 11, NA, 2, 5, NA))
setna(dfr)
dfr <- data.frame(trw = c(2.2, 5.0, 3.6, 12, 1600, -4),
                  dm = c(21, 23, 105, 24, -3, 30),
                  tnr = c(1.3, 10, 11, NA, 2, 5),
                  scol = c(1, 0, 15, 5, 4, 7),
                  fcol.cc = c(1, 15, 12, 24, 55, 20))
setna(dfr)

reyzaguirre/st4gi documentation built on March 29, 2025, 10:38 p.m.