Merge a look-up table to append new variables, names, or categories to x.

datLUTnm(
  xvar,
  x = NULL,
  uniquex = NULL,
  LUT = NULL,
  LUTvar = NULL,
  LUTnewvar = NULL,
  LUTnewvarnm = NULL,
  FIAname = FALSE,
  group = FALSE,
  NAclass = "Other",
  add0 = FALSE,
  spcdname = "COMMON_SCIENTIFIC",
  stopifmiss = FALSE,
  xtxt = NULL,
  dsn = NULL,
  dbconn = NULL,
  dbconnopen = FALSE,
  dbwrite = FALSE,
  dbreturn = TRUE,
  overwrite = TRUE,
  savedata = FALSE,
  savedata_opts = NULL,
  gui = FALSE
)

Arguments

xvar

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

x

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

uniquex

String. Unique values to match, if x is NULL.

LUT

Data frame or comma-delimited file (*.csv). Name of the file with collapsed classes (If FIAname=FALSE).

LUTvar

String. Name of variable in LUT with values matching that xvar. If LUTvar=NULL, LUTvar=xvar.

LUTnewvar

String. Name(s) of other variable(s) in the look-up table to include in join. If NULL, all other variables in table will be included.

LUTnewvarnm

String. Different name(s) for LUTnewvar. If NULL, names will default to LUTnewvar. The length of LUTnewvarnm must equal the length for LUTnewvar.

FIAname

Logical. If TRUE, get FIA reference name based on (ref_codes) within FIESTA.

group

Logical. If TRUE and FIA=TRUE, the group variables in reference table (ref_codes) are merged to data table (GROUPCD, GROUPNM).

NAclass

String. NA values in xvar will be changed to NAclass.

add0

Logical. IF TRUE, keep all codes in look up table. If FALSE, only include codes that are in x.

spcdname

String. Name for species output type ('COMMON', 'SCIENTIFIC', 'SYMBOL', 'COMMON_SCIENTIFIC').

stopifmiss

Logical. IF TRUE, stops function if missing codes in LUTx.

xtxt

String.* Name of x table for more useful information in warnings.

dsn

String. Data source name of database with x.

dbconn

Open database connection.

dbconnopen

Logica. 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 = 'datlut'.

gui

Logical. If gui, user is prompted for parameters.

Value

xLUT

The input data table with look-up table variable(s).

xLUTnm

Name of the new variable(s).

LUT

Look up table with categories.

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

For available reference tables: sort(unique(ref_codes$VARIABLE))

Author

Tracey S. Frescino

Examples

# Append forest type names using the reference table above.
ref_fortypcd <- ref_codes[ref_codes$VARIABLE == "FORTYPCD",]
WYcondlut <- datLUTnm(WYcond,
                      xvar = "FORTYPCD",
                      LUT = ref_fortypcd,
                      LUTvar = "VALUE",
                      LUTnewvar = "MEANING",
                      LUTnewvarnm = "FORTYPNM")
names(WYcondlut)
#> [1] "xLUT"   "xLUTnm" "LUT"   
WYcond2 <- WYcondlut$xLUT
head(WYcond2[WYcond2$FORTYPCD > 0, ])
#> Key: <FORTYPCD>
#>            PLT_CN CONDID COND_NONSAMPLE_REASN_CD CONDPROP_UNADJ SUBPPROP_UNADJ
#>            <char>  <int>                   <int>          <num>          <num>
#> 1: 40404762010690      1                      NA           1.00           1.00
#> 2: 40404788010690      1                      NA           1.00           1.00
#> 3: 40404943010690      2                      NA           0.50           0.50
#> 4: 40404955010690      1                      NA           1.00           1.00
#> 5: 40404967010690      2                      NA           0.25           0.25
#> 6: 40404970010690      1                      NA           0.50           0.50
#>    MICRPROP_UNADJ MACRPROP_UNADJ OWNCD OWNGRPCD RESERVCD SITECLCD STDORGCD
#>             <num>         <lgcl> <int>    <int>    <int>    <int>    <int>
#> 1:           1.00             NA    22       20        0        7        0
#> 2:           1.00             NA    31       30        0        7        0
#> 3:           0.50             NA    46       40        0        7        0
#> 4:           1.00             NA    22       20        0        7        0
#> 5:           0.25             NA    22       20        0        7        0
#> 6:           0.50             NA    46       40        0        7        0
#>    ADFORCD LIVE_CANOPY_CVR_PCT COND_STATUS_CD NF_COND_STATUS_CD FORTYPCD
#>      <int>               <int>          <int>             <int>    <int>
#> 1:      NA                  12              1                NA      182
#> 2:      NA                  11              1                NA      182
#> 3:      NA                  11              1                NA      182
#> 4:      NA                  78              1                NA      182
#> 5:      NA                  14              1                NA      182
#> 6:      NA                  15              1                NA      182
#>    STDSZCD STDAGE GSSTKCD DSTRBCD1 DSTRBYR1 DSTRBCD2 DSTRBYR2 FORTYPGRPCD
#>      <int>  <int>   <int>    <int>    <int>    <int>    <int>       <num>
#> 1:       3      6       4        0       NA        0       NA         180
#> 2:       1    148       5        0       NA        0       NA         180
#> 3:       1    195       5        0       NA        0       NA         180
#> 4:       1    120       3        0       NA        0       NA         180
#> 5:       1     96       5        0       NA        0       NA         180
#> 6:       3     25       5        0       NA        0       NA         180
#>    TIMBERCD               FORTYPNM
#>       <num>                 <char>
#> 1:        2 Rocky Mountain juniper
#> 2:        2 Rocky Mountain juniper
#> 3:        2 Rocky Mountain juniper
#> 4:        2 Rocky Mountain juniper
#> 5:        2 Rocky Mountain juniper
#> 6:        2 Rocky Mountain juniper

# Append forest type names the FIAname parameter. If the xvar is in the stored
# reference table, the name and values will automatically be appended.
WYcondlut2 <- datLUTnm(WYcond,
                       xvar = "FORTYPCD",
                       FIAname = TRUE)
names(WYcondlut2)
#> [1] "xLUT"   "xLUTnm" "LUT"   
WYcond3 <- WYcondlut2$xLUT
head(WYcond3[WYcond3$FORTYPCD > 0, ])
#> Key: <FORTYPCD>
#>            PLT_CN CONDID COND_NONSAMPLE_REASN_CD CONDPROP_UNADJ SUBPPROP_UNADJ
#>            <char>  <int>                   <int>          <num>          <num>
#> 1: 40404762010690      1                      NA           1.00           1.00
#> 2: 40404788010690      1                      NA           1.00           1.00
#> 3: 40404943010690      2                      NA           0.50           0.50
#> 4: 40404955010690      1                      NA           1.00           1.00
#> 5: 40404967010690      2                      NA           0.25           0.25
#> 6: 40404970010690      1                      NA           0.50           0.50
#>    MICRPROP_UNADJ MACRPROP_UNADJ OWNCD OWNGRPCD RESERVCD SITECLCD STDORGCD
#>             <num>         <lgcl> <int>    <int>    <int>    <int>    <int>
#> 1:           1.00             NA    22       20        0        7        0
#> 2:           1.00             NA    31       30        0        7        0
#> 3:           0.50             NA    46       40        0        7        0
#> 4:           1.00             NA    22       20        0        7        0
#> 5:           0.25             NA    22       20        0        7        0
#> 6:           0.50             NA    46       40        0        7        0
#>    ADFORCD LIVE_CANOPY_CVR_PCT COND_STATUS_CD NF_COND_STATUS_CD FORTYPCD
#>      <int>               <int>          <int>             <int>    <int>
#> 1:      NA                  12              1                NA      182
#> 2:      NA                  11              1                NA      182
#> 3:      NA                  11              1                NA      182
#> 4:      NA                  78              1                NA      182
#> 5:      NA                  14              1                NA      182
#> 6:      NA                  15              1                NA      182
#>    STDSZCD STDAGE GSSTKCD DSTRBCD1 DSTRBYR1 DSTRBCD2 DSTRBYR2 FORTYPGRPCD
#>      <int>  <int>   <int>    <int>    <int>    <int>    <int>       <num>
#> 1:       3      6       4        0       NA        0       NA         180
#> 2:       1    148       5        0       NA        0       NA         180
#> 3:       1    195       5        0       NA        0       NA         180
#> 4:       1    120       3        0       NA        0       NA         180
#> 5:       1     96       5        0       NA        0       NA         180
#> 6:       3     25       5        0       NA        0       NA         180
#>    TIMBERCD               FORTYPNM
#>       <num>                 <char>
#> 1:        2 Rocky Mountain juniper
#> 2:        2 Rocky Mountain juniper
#> 3:        2 Rocky Mountain juniper
#> 4:        2 Rocky Mountain juniper
#> 5:        2 Rocky Mountain juniper
#> 6:        2 Rocky Mountain juniper