Description Usage Arguments Details Value See Also Examples
View source: R/clean.trimCol.R
Trims columns from a data.table containing trawl data
1 | clean.trimCol(X, cols, c.add = NULL, c.drop = NULL)
|
X |
A |
cols |
Character vector of column names to have in the output; if missing, defaults to reasonable set of names. |
c.add |
A character vector of column names to append to |
c.drop |
A character vector of column names to drop from |
This function will drop 0 or more columns from a data.table passed to it (via X
). If cols
is not supplied, it is set to a reasonable set of column names:
(c("reg", "stratum", "lon", "lat", "year", "season", "datetime", "haulid", "ref", "spp", "common", "taxLvl", "species", "genus", "weight", "cnt", "effort", "wtcpue", "cntcpue", "depth", "btemp", "stemp","keep.row")
). On one hand, 23 columns seems like a lot; however, most regions have far more than this: as of the writing of this documentation, the regions have between 47 and 98 columns.
Recognizing that users are very likely to want to add or remove columns, but that typing out a full set of names can clutter clode, we added the c.add
and c.drop
arguments. These arguments will add or drop, respectively, names from cols
(and this action is take regardless of whether a vector of names is explicitly passed to cols
, or if the default is used).
If names are supplied to cols
that do not exist in X
, those columns simply will not be included, without warning. Similarly, if c.add
(c.drop
) tries to add (drop) names to (from) cols
that are not contained in X
, those columns will not be added (dropped), without warning.
Names passed to c.drop
take precedence over names passed to cols
or c.add
; e.g., if the same name is passed to both c.drop
and c.add
, it will not be included in the final data.table. The choice is somewhat arbitrary, although giving preference to dropping names is consistent with the intended use of the function.
Finally, duplicate columns will not be returned if a name is supplied to both cols
and to c.add
.
Returns NULL
invisibly. As a side effect, the columns present in the object passed as X
may be altered (removed).
clean.names
, clean.format
, clean.columns
, clean.tax
clean.trimRow
1 2 3 4 5 6 7 8 9 10 11 12 | # use a subset of Aleutian Islands
subset.index <- sort(sample(1:nrow(clean.ai),nrow(clean.ai)*0.05))
ai.eg <- clean.ai[subset.index] # small subset (5%)
# use defaults
ai.trim <- copy(ai.eg) # copy so not affect original
clean.trimCol(ai.trim) # uses default
# custom column trim
ai.trim2 <- copy(ai.eg) # copy
clean.trimCol(ai.trim2)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.