How to remove an object from a list that is not present in another list in R

Simon Besnard

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?

Simon Besnard

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

how to find elements from a list that are not present in another list in r

From Dev

How to remove strings in list from another list?

From Dev

Remove duplicate list object value from another object list

From Dev

How do I remove a non-present drive from the list?

From Dev

R remove an object from a list of vectors

From Dev

How to remove a specific object from a List<T>

From Dev

How to remove padding from a Object List Item?

From Dev

How to remove duplicates from a list of object

From Dev

How to find (and remove) a nested object from a List

From Dev

How to remove a specific object from a List<T>

From Dev

How to remove duplicates from a list of object

From Dev

How to find (and remove) a nested object from a List

From Dev

How to remove an instance of object from a list in python?

From Dev

How to remove an object from a linked list in java

From Dev

How to remove elements from a list with lambda based on another list

From Dev

how do you remove a list from another list?

From Dev

How do you remove every instance of a list from another list?

From Dev

how to eliminate elements from all vectors in a list that are present in a vecor in r

From Dev

how to eliminate elements from all vectors in a list that are present in a vecor in r

From Dev

Remove \r from list

From Dev

In Python: How to remove an object from a list if it is only referenced in that list?

From Dev

How do I remove a dictionary from a list depending on a value being present in a list in Python?

From Dev

Python - Remove a set of a list from another list

From Dev

Python - Remove a set of a list from another list

From Dev

remove Objects from a List base on another list

From Dev

How to remove a field from each object of a list of object?

From Dev

Remove object from array in List

From Dev

Remove object from list concurrently

From Dev

Remove object from list concurrently

Related Related

  1. 1

    how to find elements from a list that are not present in another list in r

  2. 2

    How to remove strings in list from another list?

  3. 3

    Remove duplicate list object value from another object list

  4. 4

    How do I remove a non-present drive from the list?

  5. 5

    R remove an object from a list of vectors

  6. 6

    How to remove a specific object from a List<T>

  7. 7

    How to remove padding from a Object List Item?

  8. 8

    How to remove duplicates from a list of object

  9. 9

    How to find (and remove) a nested object from a List

  10. 10

    How to remove a specific object from a List<T>

  11. 11

    How to remove duplicates from a list of object

  12. 12

    How to find (and remove) a nested object from a List

  13. 13

    How to remove an instance of object from a list in python?

  14. 14

    How to remove an object from a linked list in java

  15. 15

    How to remove elements from a list with lambda based on another list

  16. 16

    how do you remove a list from another list?

  17. 17

    How do you remove every instance of a list from another list?

  18. 18

    how to eliminate elements from all vectors in a list that are present in a vecor in r

  19. 19

    how to eliminate elements from all vectors in a list that are present in a vecor in r

  20. 20

    Remove \r from list

  21. 21

    In Python: How to remove an object from a list if it is only referenced in that list?

  22. 22

    How do I remove a dictionary from a list depending on a value being present in a list in Python?

  23. 23

    Python - Remove a set of a list from another list

  24. 24

    Python - Remove a set of a list from another list

  25. 25

    remove Objects from a List base on another list

  26. 26

    How to remove a field from each object of a list of object?

  27. 27

    Remove object from array in List

  28. 28

    Remove object from list concurrently

  29. 29

    Remove object from list concurrently

HotTag

Archive