Question: Set multiple attributes to a single node in R
0
gravatar for Spacebio
4 months ago by
Spacebio160
Spacebio160 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 • 205 views
ADD COMMENTlink modified 4 months ago by Selenocysteine420 • written 4 months ago by Spacebio160
3
gravatar for Selenocysteine
4 months ago by
Dublin, Ireland
Selenocysteine420 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 4 months ago by Selenocysteine420

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

ADD REPLYlink modified 4 months ago • written 4 months ago by Spacebio160

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

ADD REPLYlink modified 4 months ago • written 4 months ago by Selenocysteine420
0
gravatar for e.rempel
4 months ago by
e.rempel610
Germany, Heidelberg, COS
e.rempel610 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 4 months ago by e.rempel610

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 4 months ago • written 4 months ago by Spacebio160
0
gravatar for cpad0112
4 months ago by
cpad01124.1k
cpad01124.1k 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 4 months ago • written 4 months ago by cpad01124.1k
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: 699 users visited in the last hour