This is a simple question and I think I can probably re-invent the wheel and write something custom but I'm sure there must be an easy way to do this that I can't think of at the moment. Suppose I have a list:
l <- list("NY"=10001, "CT"=10002, "CT"=10002)
I would like a list:
list("NY"=10001, "CT"=10002)
I tried to use unique(l)
but it just returns:
list(10001, 10002)
How do I get a unique list but preserve the names assigned to the values?
Using duplicated:
l[ !duplicated(l) ]
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