Thanks for your help! I just tried with genes[!duplicated(genes[, 1:2]), ] and it works perfectly! Thank you so much!!
Hello,
I have a data.frame of genes like this:
GENE1 ACTIVATION
GENE1 INHIBITION
GENE1 ACTIVATION
GENE1 ACTIVATION
GENE2 UNKNOWN
GENE2 INHIBITION
GENE2 UNKNOWN
GENE3 ACTIVATION
GENE3 UNKNOWN
GENE3 ACTIVATION
and I would like to keep the table in the following format
GENE1 ACTIVATION
GENE1 INHIBITION
GENE2 UNKNOWN
GENE2 INHIBITION
GENE3 ACTIVATION
GENE3 UNKNOWN
I tried with the following code:
genes <- genes[!duplicated(genes[1]),]
but like that, I just get the "unique" genes of the column one, for example
GENE1 ACTIVATION
GENE2 INHIBITION
GENE3 UNKNOWN
Any suggestions? Thanks in advance.
3 answers
1) import/convert your table to a dataframe, called genes
2) run:
genes[!duplicated(genes[, 1:2]), ]
3) you can then transform this to a graph using igraph:
geneNetwork = graph.data.frame(genes)
[edit] I see that you edited because you solved it, you are welcome :)
Hi,
is it a data.frame? I am asking because you said
I have a list of genes
If it is a data.frame, you could just remove [1] from
genes <- genes[!duplicated(genes[1]),]
because duplicated can work on rows.
Sorry, my bad! It is a data.frame. But following your suggestion, I get the following:
GENE1 ACTIVATION
GENE1 INHIBITION
GENE1 ACTIVATION
GENE2 UNKNOWN
GENE2 INHIBITION
GENE2 UNKNOWN
GENE3 ACTIVATION
GENE3 UNKNOWN
GENE3 ACTIVATION
At the end it is the same result.
> genes= read.csv("test",header=F, stringsAsFactors=F, sep="")
.
> genes
V1 V2
1 GENE1 ACTIVATION
2 GENE1 INHIBITION
3 GENE1 ACTIVATION
4 GENE1 ACTIVATION
5 GENE2 UNKNOWN
6 GENE2 INHIBITION
7 GENE2 UNKNOWN
8 GENE3 ACTIVATION
9 GENE3 UNKNOWN
10 GENE3 ACTIVATION
.
> unique(genes)
V1 V2
1 GENE1 ACTIVATION
2 GENE1 INHIBITION
5 GENE2 UNKNOWN
6 GENE2 INHIBITION
8 GENE3 ACTIVATION
9 GENE3 UNKNOWN
Log in to answer this question.
Hello Spacebio!
We believe that this post does not fit the main topic of this site.
Solved
For this reason we have closed your question. This allows us to keep the site focused on the topics that the community can help with.
If you disagree please tell us why in a reply below, we'll be happy to talk about it.
Cheers!
closinga question is an action that is used by moderators to deal with wayward questions/duplicates etc. For reference, it should not be used by original poster for marking a question "solved". I am not able to "open" this question back up. Either you can open it back up or one of the site-admins may need to do so.Sorry, I didn't know. The question is open again.
No worries. You have already done the right thing by
acceptingthe correct answer so the question no longer remains inopenstate. Someone else may offer a better solution in future and then it becomes part of this thread. You are able to accept more than one solution ascorrect.