Question: Set multiple attributes to a single node in R
0
gravatar for Spacebio
12 months ago by
Spacebio180
Spacebio180 wrote:

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.

igraph attributes R • 451 views
ADD COMMENTlink modified 12 months ago by Selenocysteine510 • written 12 months ago by Spacebio180
3
gravatar for Selenocysteine
12 months ago by
Dublin, Ireland
Selenocysteine510 wrote:

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)
ADD COMMENTlink written 12 months ago by Selenocysteine510

Thanks for your help! I just tried with genes[!duplicated(genes[, 1:2]), ] and it works perfectly! Thank you so much!!

ADD REPLYlink modified 12 months ago • written 12 months ago by Spacebio180

[edit] I see that you edited because you solved it, you are welcome :)

ADD REPLYlink modified 12 months ago • written 12 months ago by Selenocysteine510
0
gravatar for e.rempel
12 months ago by
e.rempel700
Germany, Heidelberg, COS
e.rempel700 wrote:

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.

ADD COMMENTlink written 12 months ago by e.rempel700

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.

ADD REPLYlink modified 12 months ago • written 12 months ago by Spacebio180
0
gravatar for cpad0112
12 months ago by
cpad01129.9k
India
cpad01129.9k wrote:
> 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
ADD COMMENTlink modified 12 months ago • written 12 months ago by cpad01129.9k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1749 users visited in the last hour