I have two list of objects list_shp_Forest_2000_Africa
and list_shp_Deforested_2000_Africa
with different length. I only want to keep the objects from the list_shp_Forest_2000_Africa
which are in list_shp_Deforested_2000_Africa
. The common atrribute is the Tile name. I have tried the line of code below but I could not manage to get what I want.
list_shp_Forest_2000_Africa<- lapply(list_shp_Forest_2000_Africa, y=list_shp_Deforested_2000_Africa, function (x,y) {
remove(x[!x@data$Tile %in% y@data$Tile], list=ls())
})
Does somebody have an idea of a better approach?
Update answer based on Richard Herron's answer
ForestInDef <- sapply(list_shp_Forest_2000_Africa, function(x) {
as.logical(max(sapply(list_shp_Deforested_2000_Africa, function(y) identical(x@data$Tile[1], y@data$Tile[1]))))
}
)
list_shp_Forest_2000_Africa <- list_shp_Forest_2000_Africa[ForestInDef]
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments