0

In list A below, I was wondering how to remove any NULL and exactly get my desired output shown below? (my instinct says do.call() can help!)

A <- list(X = NULL, Y = list(a = matrix(1:2), b = matrix(3:4)))

# I tried the following without success:
lapply(seq_along(A), function(i) Filter(Negate(is.null), A[[i]]))

# DESIRED OUTPUT:

# [[1]]$`a`
#      [,1]
# [1,]    1
# [2,]    2

# [[2]]$b
#     [,1]
# [1,]   3
# [2,]   4

0 Answers0