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

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

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

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

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

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 6 months ago • written 6 months ago by Spacebio180
0
gravatar for cpad0112
6 months ago by
cpad01125.2k
cpad01125.2k 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 6 months ago • written 6 months ago by cpad01125.2k
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: 899 users visited in the last hour