list of unique value from two columns

dplyr, r, unique

Solution

A simple approach would be:

unique(unlist(df))
#[1] unit 1 unit 2 unit 3
#Levels: unit 1 unit 2 unit 3

Problem

I want to create list of unique value form two columns. I work with network analysis dataset (undirected graph) and my dataset looks like: ``` df <- data.frame(unit1_name = c("unit 1","unit 1", "unit 2"), unit2_name = c("unit 2","unit 3","unit 3")) ``` so I have all connections (called edges) between each elements (called nodes). As a result I want to get a list: ``` unit 1 unit 2 unit 3 ``` Of course I can write many code lines but is it possible to do it as fast as possible? Maybe in dplyr package?

Original source