Jim Tyhurst 2020-06-16
Est-ce qu’il y a un moyen d’écrire la fonction sum_is_null
auquel le
code ci-dessous fait allusion?
d <- tibble::tibble(
x = 1:3,
y = list(NULL, NA, Inf),
z = list(NULL, NULL, 0)
)
dplyr::summarise_all(
d, ~ sum_is_null # is that doable?
)
# desired output:
# x y z
# 0 1 2
d <- tibble::tibble(
x = 1:3,
y = list(NULL, NA, Inf),
z = list(NULL, NULL, 0)
)
sum_is_null <- function(x)
sum(sapply(x, is.null))
dplyr::summarise_all(d, sum_is_null)
## # A tibble: 1 x 3
## x y z
## <int> <int> <int>
## 1 0 1 2
sum_is_null <- function(x)
sum(lengths(x) < 1)
dplyr::summarise_all(d, list(sum_is_null))
## # A tibble: 1 x 3
## x y z
## <int> <int> <int>
## 1 0 1 2
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.