Description Usage Arguments Details Value Author(s) Examples
Given a list of lists, this function can be used to extract a named element from each sublist.
1 | subListExtract(L, name, simplify = FALSE, keep.names = TRUE)
|
L |
A list of named lists |
name |
The name of the element in the sublists that should be extracted. This should be a length one character vector. |
simplify |
When |
keep.names |
If |
This function is implemented in C and is intended to be faster than
calling lapply
or sapply
.
If simplify=FALSE
, a list will be returned having the same
length as L
, but with each element containing the
element named name
from the corresponding inner list of
L
.
When simplify=TRUE
, an atomic vector will be returned
containing the extracted elements. If any of the inner list elements
do not have length one or cannot be put inside an atomic vector, an
error will be raised.
Seth Falcon
1 2 3 4 5 6 7 8 9 10 11 12 13 | list_size = 500000
innerL = list(foo="foo", bar="bar")
L = rep(list(innerL), list_size)
system.time({j0 = sapply(L, function(x) x$foo)})
system.time({j1 = subListExtract(L, "foo", simplify=TRUE)})
stopifnot(all.equal(j0, j1))
LS = L[1:3]
names(LS) = LETTERS[1:3]
subListExtract(LS, "bar", simplify=TRUE)
subListExtract(LS, "bar", simplify=FALSE)
subListExtract(LS, "bar", simplify=TRUE, keep.names=FALSE)
|
Loading required package: BiocGenerics
Loading required package: parallel
Attaching package: 'BiocGenerics'
The following objects are masked from 'package:parallel':
clusterApply, clusterApplyLB, clusterCall, clusterEvalQ,
clusterExport, clusterMap, parApply, parCapply, parLapply,
parLapplyLB, parRapply, parSapply, parSapplyLB
The following objects are masked from 'package:stats':
IQR, mad, sd, var, xtabs
The following objects are masked from 'package:base':
Filter, Find, Map, Position, Reduce, anyDuplicated, append,
as.data.frame, basename, cbind, colMeans, colSums, colnames,
dirname, do.call, duplicated, eval, evalq, get, grep, grepl,
intersect, is.unsorted, lapply, lengths, mapply, match, mget,
order, paste, pmax, pmax.int, pmin, pmin.int, rank, rbind,
rowMeans, rowSums, rownames, sapply, setdiff, sort, table, tapply,
union, unique, unsplit, which, which.max, which.min
Welcome to Bioconductor
Vignettes contain introductory material; view with
'browseVignettes()'. To cite Bioconductor, see
'citation("Biobase")', and for packages 'citation("pkgname")'.
user system elapsed
0.398 0.008 0.408
user system elapsed
0.014 0.003 0.019
A B C
"bar" "bar" "bar"
$A
[1] "bar"
$B
[1] "bar"
$C
[1] "bar"
[1] "bar" "bar" "bar"
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.