sublist | R Documentation |
sublist
yields a sublist of a list ls
by filtering or extracting a subset of the list's
dimensions and levels.
sublist(ls, in_list = ls, out_list = NULL, quiet = FALSE)
ls |
The original list (as |
in_list |
A list specifying the tag and value(s) of |
out_list |
A list specifying the tag and value(s) of |
quiet |
Boolean: Hide feedback messages?
Default: |
sublist
provides a filter/slice function for lists, by specifying
a positive subset in_list
and a negative subset out_list
(both as lists, in tag and value format).
A list.
subtable
for extracting subsets of a table.
(ls <- list(n = 1:4, l = letters[1:4]))
# Trivial cases:
sublist(ls, in_list = ls)
sublist(ls, out_list = ls)
# (a) in_list only:
sublist(ls, in_list = list(l = letters[c(2, 4)], n = c(2, 4)))
sublist(ls, in_list = list(n = 4))
# NA/empty cases:
sublist(ls, in_list = NA) # returns NA
sublist(ls, in_list = list()) # returns an empty list
# Note:
sublist(ls, in_list = list(l = 4, n = 4)) # matching list elements and levels
sublist(ls, in_list = list(l = 99, n = 99)) # non-existent levels: nothing in
sublist(ls, in_list = list(ll = 99, nn = 99)) # heuristics match list elements
# (b) out_list only:
sublist(ls, out_list = list(l = letters[c(2, 4)], n = c(2, 4)))
sublist(ls, out_list = list(n = 3, l = "c"))
# NA/empty cases:
sublist(ls, out_list = NA) # returns NA
sublist(ls, out_list = list()) # returns original list
# Note:
sublist(ls, out_list = list(l = 4, n = 4)) # matching list elements and levels
sublist(ls, out_list = list(l = 99, n = 99)) # non-existent levels: nothing out
sublist(ls, out_list = list(ll = 99, nn = 99)) # heuristics match list elements
# (c) in_list AND out_list:
sublist(ls, in_list = list(n = 3:4, l = c("c", "a")), out_list = list(l = "c"))
sublist(ls, in_list = list(n = 3:4, l = c("c", "a")), out_list = list(n = 4, l = "c"))
# removing everything:
sublist(ls, in_list = list(n = 4:3), out_list = list(n = 3:4))
sublist(ls, in_list = list(l = c("c", "a")), out_list = list(l = c("a", "c")))
sublist(ls, in_list = list(n = 3:4, l = c("a", "c")),
out_list = list(n = 4:3, l = c("c", "a")))
# Note: Tags can be used repeatedly and empty list elements are dropped:
sublist(ls, out_list = list(l = c("c", "b"), n = 2:3))
sublist(ls, out_list = list(l = c("c", "b"), n = 2:3, l = c("a", "d")))
sublist(ls, out_list = list(l = c("c", "b"), n = 2:3, l = c("a", "d"), n = 1:4))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.