Given a nested list of numeric vectors like
l = list( a = list(1:2, 3:5), b = list(6:10, 11:16))
If I want to apply a function, say length
, of the "index 1 / first" numeric vectors I can do it using the subset function [[
:
> sapply(lapply(l, "[[", 1), length)
a b
2 5
I cant figure how to supply arbitrary indeces to [[
in order to get length of (in this example) both vectors in every sub-list (a naive try : sapply(lapply(l, "[[", 1:2), length)
).