Вы можете использовать RuleBasedNumberFormat. например, результат даст вам Девяносто
ULocale locale = новый ULocale (Locale.US); // us english Double d = Double.parseDouble (90); NumberFormat formatter = new RuleBasedNumberFormat (locale, RuleBasedNumberFormat.SPELLOUT); Строковый результат = formatter.format (d);
Он поддерживает широкий диапазон языков.
Вот еще один вариант:
Filter(Negate(is.null), x)
x[!sapply(x,is.null)]
Это обобщает на любое логическое утверждение о списке, просто суб в логике для «is.null».
Как насчет:
x[!unlist(lapply(x, is.null))]
Вот краткое описание того, что происходит.
lapply
сообщает нам, какие элементы являются NULL
R> lapply(x, is.null)
$a
[1] FALSE
$b
[1] FALSE
$c
[1] TRUE
R> unlist(lapply(x, is.null))
a b c
FALSE FALSE TRUE
TRUE
на FALSE
: R> !unlist(lapply(x, is.null))
a b c
TRUE TRUE FALSE
x[!unlist(lapply(x, is.null))]
Проще и, скорее всего, быстрее, чем указано выше, для списков любых нерекурсивных (в смысле is.recursive
) значений:
example_1_LST <- list(NULL, a=1.0, b=Matrix::Matrix(), c=NULL, d=4L)
example_2_LST <- as.list(unlist(example_1_LST, recursive=FALSE))
str(example_2_LST)
печатает:
List of 3
$ a: num 1
$ b:Formal class 'lsyMatrix' [package "Matrix"] with 5 slots
.. ..@ x : logi NA
.. ..@ Dim : int [1:2] 1 1
.. ..@ Dimnames:List of 2
.. .. ..$ : NULL
.. .. ..$ : NULL
.. ..@ uplo : chr "U"
.. ..@ factors : list()
$ d: int 4
base::
и utils::
.
– Rich Scriven
12 December 2015 в 22:19