igraph-help
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[igraph] Coercing vertex/edge attributes to new types


From: Alex D'Amour
Subject: [igraph] Coercing vertex/edge attributes to new types
Date: Thu, 14 May 2009 12:08:35 -0400

All,

I'm having a problem with a network where edges have an "appyear"
attribute, which is a four-digit number representing a year.
Unfortunately, I imported the appyear as text, and would like to
change it to a numeric attribute.

I would expect that the easiest way to do this would be:

E(g)$appyear <- as.numeric(E(g)$appyear)

But this doesn't change the attribute -- they remain character strings.

I also tried, the following, but it caused no change:

class(E(g)$appyear) <- "numeric"
class(E(g)$appyear)
[1] "character"

The only way that I could make this type change happen was break the
abstraction barrier and delve into the igraph object's list structure:

g[[9]][[4]][["appyear"]] <- as.numeric(g[[9]][[4]][["appyear"]])

or

class(g[[9]][[4]][["appyear"]]) <- "numeric"

Interestingly, converting from numeric to character works as expected
using the standard igraph interface:

E(g)$appyear <- as.character(E(g)$appyear)

or

class(E(g)$appyear) <- "character"

Both of these generate character strings.

Is there a reason that coercion only works in one direction in this
case via the standard igraph interface? I understand that there are a
million different ways to do this, including storing the attribute in
a vector, converting that, then dropping and adding the appyear
attribute, but this seems like the kind of thing you _should_ be able
to do via igraph's interface.

Thanks,
Alex




reply via email to

[Prev in Thread] Current Thread [Next in Thread]