This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Filtering materials of two columns in R

I have a two column dataset as given below. I want to add a third column which will contain all genes from column 1 and 2, but none of the genes should repeat. How can I do this in R?

ID        ID2
Gene1     Gene3
Gene1     Gene5
Gene2     Gene7
Gene2     Gene4
Gene3     Gene6
Gene3     Gene8
r

please add an example of column 3

The example of column 3 is given below. It contains all characters of col 1 and 2 but genes names do not repeat

Gene1
Gene2
Gene3
Gene4
Gene5
Gene6
Gene7
Gene8

1 answer

Select the two columns (df['ID'], df['ID2']), combine them to a vector (e.g. c()), use the unique() function two remove duplicates. But adding the new vector to the data.frame using cbind will not be possible since it has different length than the original dataframe

It is okay, if I output the column separately

The suggestion worked with a little modification. Thanks a lot..

Log in to answer this question.