rep(10, 10) |>
map(sample, 5) |>
keep(function(x) mean(x) > 6)
# Or use a formula
rep(10, 10) |>
map(sample, 5) |>
keep(\(x) mean(x) > 6)
# Using a string instead of a function will select all list elements
# where that subelement is TRUE
x <- rerun(5, a = rbernoulli(1), b = sample(10))
x
x |> keep("a")
x |> discard("a")
# compact() discards elements that are NULL or that have length zero
list(a = "a", b = NULL, c = integer(0), d = NA, e = list()) |>
compact()
Run the code above in your browser using DataLab