BiocGenerics (version 0.18.0)

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

Description

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.

Usage

lengths(x, use.names=TRUE)

Arguments

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

Value

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.

Examples

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

library(S4Vectors)
showMethods("lengths")
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(
    a=letters[1:10],
    i=101:110,
    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