I have a big list (A
) of lists of SpatialPolygonsDataFrames. Some of the lists have null values (means there is no SpatialPolygonsDataFrame). I tried :
A[!sapply(unlist(A, recursive=FALSE), is.null)]
But with no result and then I tried:
A_nonulls=lapply(A, na.omit)
What is the right way to remove the null of every list in the bigger list?
EDIT:
I can't do str(A)because A has 1000 lists and is huge. The first elements from the first list is like :
[[1]]
NULL
[[2]]
NULL
[[3]]
NULL
[[4]]
NULL
[[5]]
class : SpatialPolygons
features : 1
extent : 722951.5, 726848.9, 4325874, 4329654 (xmin, xmax, ymin, ymax)
So I want to removw the nulls and keep only the not empty elements.
another option using Hadley's terrific purrr package:
library(purrr)
compact(A)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With