Generates a pivot table of values by x row and y column.
Usage
datPivot(
x,
pvar,
xvar,
yvar,
pfun = sum,
xfilter = NULL,
NAto0 = TRUE,
dropNAxvar = TRUE,
dropNAyvar = TRUE,
pvar.round = 6,
returnDT = FALSE,
savedata = FALSE,
savedata_opts = NULL,
gui = FALSE
)
Arguments
- x
Dataframe. Table with pivot variables.
- pvar
String. The name of the variable for pivot table values.
- xvar
String. The name of the variable for rows.
- yvar
String. The name of the variable for columns.
- pfun
Function. The name of the function to use for pivot table values (ex. sum, mean, max).
- xfilter
String. A filter to subset the datatable table x before pivoting (ex. "STATUSCD == 1").
- NAto0
Logical. If TRUE, converts NA values to 0.
- dropNAxvar
Logical. If TRUE, removes columns that are NA.
- dropNAyvar
Logical. If TRUE, removes rows that have NA values.
- pvar.round
Integer. Number to round pvar values to.
- returnDT
Logical. If TRUE, returns a datatable.
- savedata
Logical. If TRUE, writes output 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 = 'datpivot'.
- gui
Logical. If TRUE, pop-up windows will appear for user-interface.
Examples
# Pivot WYcond table
datPivot(x = FIESTA::WYcond,
pvar = "CONDPROP_UNADJ",
xvar = "FORTYPCD",
yvar = "STDSZCD")
#> FORTYPCD X1 X2 X3 X5
#> 1 182 23.232457 3.00000 4.500000 0.00
#> 2 184 15.500000 0.00000 1.000000 0.00
#> 3 185 0.750000 0.00000 0.000000 0.00
#> 4 201 27.850205 5.50000 8.500000 0.00
#> 5 221 39.967833 2.25000 2.750000 0.00
#> 6 265 16.250000 3.25000 3.250000 0.00
#> 7 266 48.250000 12.51122 10.500000 0.00
#> 8 268 28.378370 7.50000 9.488778 0.00
#> 9 269 1.000000 0.00000 0.000000 0.00
#> 10 281 43.948767 39.42715 34.680757 0.00
#> 11 366 3.500000 0.00000 7.593481 0.00
#> 12 367 4.371145 5.75000 7.500000 0.00
#> 13 509 1.000000 1.75000 2.000000 0.00
#> 14 517 0.000000 0.00000 1.000000 0.00
#> 15 703 3.027328 0.25000 1.000000 0.00
#> 16 706 0.000000 0.50000 0.000000 0.00
#> 17 901 2.000000 8.11529 19.250000 0.00
#> 18 999 0.000000 0.00000 0.000000 40.75
# Pivot WYtree table
datPivot(x = FIESTA::WYtree,
pvar = "TPA_UNADJ",
xvar = "SPCD",
yvar = "STATUSCD",
pfun = mean,
NAto0 = TRUE)
#> SPCD X1 X2
#> 1 101 17.168267 6.018046
#> 2 106 6.018046 0.000000
#> 3 108 15.727388 6.018046
#> 4 113 17.941252 6.018046
#> 5 122 11.996865 6.018046
#> 6 19 20.823612 6.018046
#> 7 202 11.495163 6.018046
#> 8 313 6.018046 6.018046
#> 9 375 74.965282 6.018046
#> 10 475 6.018046 6.018046
#> 11 544 6.018046 0.000000
#> 12 65 8.009302 6.018046
#> 13 66 13.168130 6.018046
#> 14 745 6.018046 6.018046
#> 15 746 22.934468 6.018046
#> 16 749 8.669863 6.018046
#> 17 823 13.943016 6.018046
#> 18 93 14.129486 6.018046
#> 19 96 29.000458 0.000000