logo

Dismantling a list in R, Removing Duplicate Elements 📂R

Dismantling a list in R, Removing Duplicate Elements

Overview

Dealing with all sorts of unrefined data, the list data type in R is especially useful in organizing data. However, on the flip side, accessing data can be a bit cumbersome and disadvantageous in locating the desired content.

In this case, breaking down the list data type through the unlist() function makes this manipulation much more convenient.

20180911_170246.png

The unique() function removes all duplicate elements in the received array, leaving only one of each. It can perform a similar role to when you would use the set data type in Python.

Code

Here is an example code.

x<-list(A=c(3,2,5,3),B=c(2.2,5,3,2.0)); x
unlist(x)
unique(unlist(x))