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)
你可以试试这个
A[!sapply(A, is.null)]
我们可以试试Filter
Filter(Negate(is.null), A)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.