5

I have a data.frame containing values I want to use as attributes in a network file.

When I try to assign the values as attributes manually half of them work but the other half show this error. I have looked closely at the data and I cannot see anything intrinsic that should be causing this.

Format vector input (this one works)

visitgo2n%v%"hhid" <- attr2$hhid

Here is the error:

"Error in set.vertex.attribute(x, attrname = attrname, value = value) : 
  Inappropriate value given in set.vertex.attribute."

I have tried removing white space but this does not work.

I have also tried entering the vectors in this way but I get the same error:

for (n in names(attr2)) {
  visitgo2n %v% n <- attr2[[n]]
}

What could be causing half the vectors to be 'inappropriate', what values are appropriate?

Tom Davidson
  • 737
  • 1
  • 8
  • 16
  • 1
    Please include a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). Be sure to include all the packages and version numbers you are using (`sessionInfo()`). – MrFlick Feb 18 '15 at 02:48
  • what are the values in attr2$hhid? btw, looks to me like you are using the 'network' package not igraph as tag suggests – skyebend Jul 10 '15 at 23:35
  • @tom Davidson: The answer provided by ibakecookeies seems to be right. If the variable is not a factor this wouldn't happen. Please mark the answer right. ~bharath –  Feb 26 '17 at 23:13
  • What if the variable is numeric? https://stackoverflow.com/questions/52357757/numeric-attributes-are-being-alpha-sorted-in-ggnet2 – andyczerwonka Sep 16 '18 at 20:17

1 Answers1

13

So this is a bit late, but I ran into the same issue just today and figured out that this is probably because the variable is a factor. You need to convert it to a character like so:

attr2$hhid <-  as.character(attr2$hhid)

This should fix the issue.

ibakecookies
  • 144
  • 2
  • 6
  • 1
    See this issue for the same problem. https://stackoverflow.com/questions/52357757/numeric-attributes-are-being-alpha-sorted-in-ggnet2 – andyczerwonka Sep 16 '18 at 20:16