If we have a list, and each item can have different length. For example:
l <- list(c(1, 2), c(3, 4,5), c(5), c(6,7))
(In order to be cl
We can create a function using sapply
sapply
fun1 <- function(lst, n){ sapply(lst, `[`, n) } fun1(l, 1) #[1] 1 3 5 6 fun1(l, 2) #[1] 2 4 NA 7