datLUTclass: Data - Create a variable with classified values.

View source: R/datLUTclass.R

datLUTclassR Documentation

Data - Create a variable with classified values.

Description

Merge a look-up table to define categories of continuous data in x (e.g., DIA). Adds a variable to x, defining as: xvar >= MIN (and xvar < MAX).

Usage

datLUTclass(
  x,
  xvar = NULL,
  LUT = NULL,
  minvar = NULL,
  maxvar = NULL,
  cutbreaks = NULL,
  cutlabels = NULL,
  LUTclassnm = NULL,
  label.dec = 1,
  NAto0 = FALSE,
  vars2keep = NULL,
  keepcutbreaks = FALSE,
  dsn = NULL,
  dbconn = NULL,
  dbconnopen = FALSE,
  dbwrite = FALSE,
  dbreturn = TRUE,
  overwrite = TRUE,
  savedata = FALSE,
  savedata_opts = NULL,
  gui = FALSE
)

Arguments

x

Data frame or comma-delimited file (*.csv) or table in dsn. The data table with variable to classify.

xvar

String. Name of variable in the data table to join to.

LUT

Data frame or comma-delimited file (*.csv). Name of the look-up table with collapsed classes. Lookup table should include minimum values for classes, maximum values for classes, and a name of class (i.e., LUTclassnm). Maximum values and names are optional.

minvar

String. If LUT is not null, name of variable with minimimum class value (>= minvar).

maxvar

String. Optional. If LUT is not null, name of variable with maximum class value (<= maxvar).

cutbreaks

Numeric vector. Vector of numbers for minimum class values.

cutlabels

String vector. Optional. Vector of names for classes. If NULL, class names are generated from cutbreaks.

LUTclassnm

String. Optional. Name of classified variable in x. If LUT is not null and class names are included, this is the name of variable with class names. If NULL, a class names are generated from minvar or minvar and maxvar with default name equal to 'xvar'CL.

label.dec

Integer. Number of decimals to include in label.

NAto0

Logical. If TRUE, converts NA values to 0 before classification.

vars2keep

String vector. Variable names from LUT to keep (append) to x.

keepcutbreaks

Logical. If TRUE, the cutbreaks used for creating classes are appended to dataset.

dsn

String. Data source name of database with x.

dbconn

Open database connection.

dbconnopen

Logical. If TRUE, keep database connection open.

dbwrite

Logical. If TRUE, write class column to database table x.

dbreturn

Logical. If TRUE, return table with class column.

overwrite

Logical. If TRUE, and the class name already exists in x, overwrites class name.

savedata

Logical. If TRUE, saves data to outfolder.

savedata_opts

List. See help(savedata_options()) for a list of options. Only used when savedata = TRUE. If out_layer = NULL, default = 'datlutcl'.

gui

Logical. If gui, user is prompted for parameters.

Details

Use datLUTclass() to prompt for input.

Value

xLUT

Input data table with look-up table variable(s).

LUTclassnm

Name of the classified variable.

LUT

Look-up table with categories.

tablst If savedata = TRUE, a comma-delimited file is output to the outfolder as outfn. If outfn = NULL, the name of the file will be datlut_'date'.csv.

Note

The look-up table format must be similar to the following table Set LUTclassnm = VARCLNM. MAX and VALCLNM columns are optional.

MIN MAX VARCLNM
1.0 4.9 1
5.0 9.9 2
10.0 15.0 3
15.0 19.9 4
20.0 24.9 5
25.0 49.9 6

Author(s)

Tracey S. Frescino

Examples

head(FIESTA::ref_diacl2in)
WYtreelut <- datLUTclass(FIESTA::WYtree,
                         xvar = "DIA",
                         LUT = FIESTA::ref_diacl2in,
                         LUTclassnm = "DIACL2IN")
names(WYtreelut)
head(WYtreelut$xLUT)
table(WYtreelut$xLUT$DIACL2IN)

WYtreelut2 <- datLUTclass(FIESTA::WYtree,
                          xvar = "DIA",
                          cutbreaks = c(1, 5, 25, 50, 100),
                          LUTclassnm = "DIACL2IN")
names(WYtreelut2)
head(WYtreelut2$xLUT)
table(WYtreelut2$xLUT$DIACL2IN)

#' Create look-up table of stand age classes
MIN <- c(0, 20, 40, 60, 80, 101)
STDAGENM <- c("0-20", "21-40", "41-60", "61-80", "81-100", "101+")
stdagelut <- data.frame(MIN = MIN, STDAGENM = STDAGENM)
stdagelut

WYcondlut <- datLUTclass(FIESTA::WYcond,
                         xvar = "STDAGE",
                         LUT = stdagelut,
                         LUTclassnm = "STDAGENM")
names(WYcondlut)
head(WYcondlut$xLUT)
table(WYcondlut$xLUT$STDAGENM)

FIESTA documentation built on Nov. 22, 2023, 1:07 a.m.