my nested list looks like this:
myList <- list(structure(list(id = 1:3, value = c(22, 33, 44),
code = c("943", "943", "3a0"),
product = c("Product 1", "Product 1", "Product 1")),
row.names = c(NA,-3L),
class = c("data.table", "data.frame")),
structure(list(id = 1:3, value = c(22, 33, 44),
code = c("943", "94f", "3a0"),
product = c("Product 2", "Product 2", "Product 2")),
row.names = c(NA,-3L),
class = c("data.table", "data.frame")),
structure(list(id = 1:3, value = c(22, 33, 44),
code = c("977", "943", "3a0"),
product = c("Product 3", "Product 3", "Product 3")),
row.names = c(NA,-3L),
class = c("data.table", "data.frame")))
i want to remove all list objects that have more than one list element with the same code. For example the first object [[1]] has two entries that have the code 943. I want to remove the entire object and keep only those that do not have any duplicates.
The expected outcome would therefore be: myList <- list(
structure(list(id = 1:3, value = c(22, 33, 44),
code = c("943", "94f", "3a0"),
product = c("Product 2", "Product 2", "Product 2")),
row.names = c(NA,-3L),
class = c("data.table", "data.frame")),
structure(list(id = 1:3, value = c(22, 33, 44),
code = c("977", "943", "3a0"),
product = c("Product 3", "Product 3", "Product 3")),
row.names = c(NA,-3L),
class = c("data.table", "data.frame")))
I was thinking of using and lapply, but i couldnt get it to qwork
any(duplicated(myList[[1]]$code))
any ides or suggestion?
this seems like a relatively simple problem, but i cant figure it out