BiocGenerics (version 0.18.0)

lengths: Lengths of the list elements of a list-like object


Get the length of each list element of a list-like object.

NOTE: This man page is for the lengths S4 generic function defined in the BiocGenerics package. See ?base::lengths for the default method (defined in the base package). Bioconductor packages can define specific methods for list-like objects not supported by the default method.


lengths(x, use.names=TRUE)


A list-like object. Can also be a vector-like object that is not list-like, in which case the result is trivial.
See ?base::lengths for a description of this argument.


See ?base::lengths for the value returned by the default method.Specific methods defined in Bioconductor packages should behave as consistently as possible with the default method.

See Also

  • base::lengths for the default lengths method.

  • showMethods for displaying a summary of the methods defined for a given generic function.

  • selectMethod for getting the definition of a specific method.

  • lengths,Vector-method in the S4Vectors package for an example of a specific lengths method (defined for Vector objects).

  • BiocGenerics for a summary of all the generics defined in the BiocGenerics package.


Run this code
lengths  # note the dispatch on the 'x' arg only
selectMethod("lengths", "ANY")  # the default method

selectMethod("lengths", "Vector")  # the "lengths" method for Vector
                                   # objects

## Difference between default method and method for Vector objects:
groups <- c("group1", "group2")
df <- data.frame(
    group=rep(factor(groups, levels=groups), c(6, 4))
x1 <- split(df, df$group)
x2 <- split(DataFrame(df), df$group)
lengths(x1)  # dispatch on default method
lengths(x2)  # dispatch on method for Vector objects

Run the code above in your browser using DataCamp Workspace