remove NA values from list elements
Usage
rmNAs(
x,
naValue = NULL,
rmNULL = FALSE,
nullValue = naValue,
rmInfinite = TRUE,
infiniteValue = NULL,
rmNAnames = FALSE,
verbose = FALSE,
...
)
Arguments
- x
list
of vectorsNULL or single replacement value for NA entries. If NULL, then NA entries are removed from the result.
- rmNULL
logical
whether to replace NULL entries withnullValue
- nullValue
NULL or single replacement value for NULL entries. If NULL, then NULL entries are removed from the result.
- rmInfinite
logical
whether to replace Infinite values with infiniteValue- infiniteValue
value to use when rmInfinite==TRUE to replace entries which are Inf or -Inf.
- rmNAnames
logical
whether to remove entries which have NA as the name, regardless whether the entry itself is NA.- verbose
logical
whether to print verbose output- ...
additional arguments are ignored.
Value
list
where NA entries were removed or replaced with naValue
in each vector. Empty list
elements are optionally removed when
rmNULL=TRUE
, or replaced with nullValue
when defined. When
rmInfinite=TRUE
then infinite values are either removed, or
replaced with infiniteValue
when defined.
Details
This function removes NA
values from vectors in a list
,
applying the same logic used in rmNA()
to each vector.
It is somewhat optimized, in that it checks for list elements
that have NA
values before applying rmNA()
.
However, it calls rmNA()
iteratively on each vector that
contains NA
in order to preserve the class
(factor, character, numeric, etc.) of each vector.
It also optionally applies convenience functions rmNULL()
and rmInfinite()
as relevant.
See also
Other jam practical functions:
breakDensity()
,
call_fn_ellipsis()
,
checkLightMode()
,
check_pkg_installed()
,
colNum2excelName()
,
color_dither()
,
exp2signed()
,
getAxisLabel()
,
isFALSEV()
,
isTRUEV()
,
jargs()
,
kable_coloring()
,
lldf()
,
log2signed()
,
middle()
,
minorLogTicks()
,
newestFile()
,
printDebug()
,
reload_rmarkdown_cache()
,
renameColumn()
,
rmInfinite()
,
rmNA()
,
rmNULL()
,
setPrompt()
Examples
testlist <- list(
A=c(1, 4, 5, NA, 11),
B=c("B", NA, "C", "Test"))
rmNAs(testlist)
#> $A
#> [1] 1 4 5 11
#>
#> $B
#> [1] "B" "C" "Test"
#>
testlist2 <- list(
A=c(1, 4, 5, NA, 11, Inf),
B=c(11, NA, 19, -Inf))
rmNAs(testlist2, naValue=-100, infiniteValue=1000)
#> $A
#> [1] 1 4 5 -100 11 1000
#>
#> $B
#> [1] 11 -100 19 -1000
#>