lengths for recursive lists
Arguments
- x
listor vector- doSum
logicalindicating whether to return the overall sum of lengths. WhenNULLit will return the aggregate length of each list element inx. WhenFALSEit will return the same list structure of x, with the length of each. WhenTRUEit will return the total length of all elements inxas one value.- ...
additional parameters are ignored
Value
integer value, vector, or list:
When
doSum is NULL(default) it returns anintegervector with lengthlength(x)and namesnames(x), whose values are the total number of elements in each item inxafter runningbase::unlist().When
doSum=="TRUE", it returns the singleintegerlength of all elements inx.When
doSum=="FALSE", it returns the full structure ofxwith theintegerlength of each element.
The parameter doSum is intended for internal use, during
recursive calls of rlengths() to itself. When doSum is NULL or
TRUE, recursive calls to rlengths() set doSum=TRUE.
Details
This function takes a list as input, and returns the length
of each list element after running base::unlist().
See also
Other jam list functions:
cPaste(),
heads(),
jam_rapply(),
list2df(),
mergeAllXY(),
mixedSorts(),
rbindList(),
relist_named(),
sclass(),
sdim(),
uniques(),
unnestList()
Examples
x <- list(
A=list(
A1=nameVector(1:3, letters[1:3]),
A2=list(
A1a=nameVector(4:7, letters[4:7]),
A1b=nameVector(11:14, letters[11:14]))),
B=list(B1=nameVector(1:9, letters[1:9]),
B2=nameVector(20:25, letters[20:25])));
# default lengths(x) shows length=2 for A and B
lengths(x)
#> A B
#> 2 2
# rlengths(x) shows the total length of A and B
rlengths(x)
#> A B
#> 11 15