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.
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 |
Examples
head(FIESTA::ref_diacl2in)
#> MIN MAX DIACL2IN
#> 1 1 2.9 1.0-2.9
#> 2 3 4.9 3.0-4.9
#> 3 5 6.9 5.0-6.9
#> 4 7 8.9 7.0-8.9
#> 5 9 10.9 9.0-10.9
#> 6 11 12.9 11.0-12.9
WYtreelut <- datLUTclass(FIESTA::WYtree,
xvar = "DIA",
LUT = FIESTA::ref_diacl2in,
LUTclassnm = "DIACL2IN")
names(WYtreelut)
#> [1] "xLUT" "LUTclassnm" "LUT"
head(WYtreelut$xLUT)
#> PLT_CN CONDID SUBP TREE STATUSCD SPCD SPGRPCD DIA HT TREECLCD
#> 1 40404729010690 1 1 1 2 113 24 7.7 18 3
#> 2 40404729010690 1 1 2 1 66 23 10.8 14 3
#> 3 40404729010690 1 1 3 2 113 24 5.2 23 3
#> 4 40404729010690 1 1 4 1 113 24 5.2 18 2
#> 5 40404729010690 1 3 1 1 113 24 8.8 21 3
#> 6 40404729010690 1 4 1 1 113 24 8.9 28 3
#> AGENTCD STANDING_DEAD_CD VOLCFNET VOLCFGRS VOLBFNET TPA_UNADJ DRYBIO_AG
#> 1 10 1 1.001201 1.820365 NA 6.018046 68.32740
#> 2 NA NA NA NA NA 6.018046 128.28703
#> 3 10 1 0.466414 0.848025 NA 6.018046 40.24585
#> 4 NA NA 0.630180 0.630180 NA 6.018046 40.61207
#> 5 NA NA 2.491559 2.931246 NA 6.018046 144.25115
#> 6 NA NA 3.824139 4.202350 NA 6.018046 182.53588
#> CARBON_AG BA DIACL2IN
#> 1 34.43701 0.3233677 7.0-8.9
#> 2 61.19291 0.6361546 9.0-10.9
#> 3 20.28391 0.1474762 5.0-6.9
#> 4 19.49379 0.1474762 5.0-6.9
#> 5 69.24055 0.4223578 7.0-8.9
#> 6 87.61722 0.4320113 7.0-8.9
table(WYtreelut$xLUT$DIACL2IN)
#>
#> 1.0-2.9 3.0-4.9 5.0-6.9 7.0-8.9 9.0-10.9 11.0-12.9 13.0-14.9 15.0-16.9
#> 1373 530 5381 3972 2716 1622 935 555
#> 17.0-18.9 19.0-20.9 21.0-22.9 23.0-24.9 25.0-26.9 27.0-28.9 29.0-30.9 31.0-32.9
#> 324 232 121 73 46 26 11 12
#> 33.0-34.9 35.0-36.9 37.0-38.9 39.0-40.9 41.0-42.9 43.0-44.9 45.0-46.9 47.0-48.9
#> 5 6 0 2 0 0 0 0
#> 49.0-50.9 51.0-52.9 53.0-54.9 55.0-56.9 57.0-58.9 59.0-60.9 61.0-62.9 63.0-64.9
#> 0 0 0 0 0 0 0 1
#> 65.0-66.9 67.0-68.9 69.0-70.9 71.0-72.9 73.0-74.9 75.0-76.9 77.0-78.9 79.0-80.9
#> 0 0 0 0 0 0 0 0
WYtreelut2 <- datLUTclass(FIESTA::WYtree,
xvar = "DIA",
cutbreaks = c(1, 5, 25, 50, 100),
LUTclassnm = "DIACL2IN")
names(WYtreelut2)
#> [1] "xLUT" "LUTclassnm" "LUT"
head(WYtreelut2$xLUT)
#> PLT_CN CONDID SUBP TREE STATUSCD SPCD SPGRPCD DIA HT TREECLCD
#> 1 40404729010690 1 1 1 2 113 24 7.7 18 3
#> 2 40404729010690 1 1 2 1 66 23 10.8 14 3
#> 3 40404729010690 1 1 3 2 113 24 5.2 23 3
#> 4 40404729010690 1 1 4 1 113 24 5.2 18 2
#> 5 40404729010690 1 3 1 1 113 24 8.8 21 3
#> 6 40404729010690 1 4 1 1 113 24 8.9 28 3
#> AGENTCD STANDING_DEAD_CD VOLCFNET VOLCFGRS VOLBFNET TPA_UNADJ DRYBIO_AG
#> 1 10 1 1.001201 1.820365 NA 6.018046 68.32740
#> 2 NA NA NA NA NA 6.018046 128.28703
#> 3 10 1 0.466414 0.848025 NA 6.018046 40.24585
#> 4 NA NA 0.630180 0.630180 NA 6.018046 40.61207
#> 5 NA NA 2.491559 2.931246 NA 6.018046 144.25115
#> 6 NA NA 3.824139 4.202350 NA 6.018046 182.53588
#> CARBON_AG BA DIACL2IN
#> 1 34.43701 0.3233677 5-24.9
#> 2 61.19291 0.6361546 5-24.9
#> 3 20.28391 0.1474762 5-24.9
#> 4 19.49379 0.1474762 5-24.9
#> 5 69.24055 0.4223578 5-24.9
#> 6 87.61722 0.4320113 5-24.9
table(WYtreelut2$xLUT$DIACL2IN)
#>
#> 1-4.9 5-24.9 25-49.9 50+
#> 1903 15931 108 1
#' 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
#> MIN STDAGENM
#> 1 0 0-20
#> 2 20 21-40
#> 3 40 41-60
#> 4 60 61-80
#> 5 80 81-100
#> 6 101 101+
WYcondlut <- datLUTclass(FIESTA::WYcond,
xvar = "STDAGE",
LUT = stdagelut,
LUTclassnm = "STDAGENM")
names(WYcondlut)
#> [1] "xLUT" "LUTclassnm" "LUT"
head(WYcondlut$xLUT)
#> PLT_CN CONDID COND_NONSAMPLE_REASN_CD CONDPROP_UNADJ SUBPPROP_UNADJ
#> 1 40404728010690 1 NA 1 1
#> 2 40404729010690 1 NA 1 1
#> 3 40404730010690 1 NA 1 1
#> 4 40404731010690 1 NA 1 1
#> 5 40404733010690 1 NA 1 1
#> 6 40404734010690 1 NA 1 1
#> MICRPROP_UNADJ MACRPROP_UNADJ OWNCD OWNGRPCD RESERVCD SITECLCD STDORGCD
#> 1 1 NA 46 40 0 NA NA
#> 2 1 NA 46 40 0 7 0
#> 3 1 NA 11 10 0 6 0
#> 4 1 NA 22 20 0 NA NA
#> 5 1 NA 46 40 0 NA NA
#> 6 1 NA 22 20 0 NA NA
#> ADFORCD LIVE_CANOPY_CVR_PCT COND_STATUS_CD NF_COND_STATUS_CD FORTYPCD STDSZCD
#> 1 NA 0 2 NA NA NA
#> 2 NA 17 1 NA 366 1
#> 3 206 41 1 NA 201 1
#> 4 NA 0 2 NA NA NA
#> 5 NA 0 2 NA NA NA
#> 6 NA 0 2 NA NA NA
#> STDAGE GSSTKCD DSTRBCD1 DSTRBYR1 DSTRBCD2 DSTRBYR2 FORTYPGRPCD TIMBERCD
#> 1 NA NA NA NA NA NA NA NA
#> 2 46 5 0 NA 0 NA 360 2
#> 3 220 3 0 NA 0 NA 200 1
#> 4 NA NA NA NA NA NA NA NA
#> 5 NA NA NA NA NA NA NA NA
#> 6 NA NA NA NA NA NA NA NA
#> STDAGENM
#> 1 <NA>
#> 2 41-60
#> 3 101+
#> 4 <NA>
#> 5 <NA>
#> 6 <NA>
table(WYcondlut$xLUT$STDAGENM)
#>
#> 0-20 21-40 41-60 61-80 81-100 101+
#> 144 42 14 43 89 258