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 DataLab