igraph's "assortativity" function returns NaN if all attributes are identical. Why? I am trying to use igraph's assortativity function. It returns positive values if more similar nodes have similar attributes and negative values otherwise.
Indeed, if I randomly generate attributes for a graph, this is the case:
gg<-random.graph.game(50,0.3,"gnp",directed=T)
V(gg)$group<-sample(1:7,50,replace=T)
assortativity(gg, as.numeric(V(gg)$group))
[1] 0.002059966
V(gg)$group
 [1] 1 4 7 2 6 5 4 3 3 5 5 1 4 1 3 3 2 4 1 3 7 7 1 1 2 3 6 2 7 4 2 4 1 6 1 2 2 5 2 1 7 1 1 3 6 1 3 6 7 2

This all looks right and makes sense. However, for my dataset, I have a network for a particular situation where all the attributes are identical. Theoretically, this should be high homophily/assortativity. But to the contrary, it returns NaN. Does anyone know why this is and what the remedy could be?
V(gg)$group<-7
assortativity(gg, as.numeric(V(gg)$group))
[1] NaN

EDIT: I have found a solution to this, although I cannot explain why this is the case. It seems to be something about the whole number/integer. If I add .001 as a constant to each number in the graph's attribute, to get 7.001 instead of 7, it returns the expected assortativity coefficient of "1". See below:
gg<-random.graph.game(50,0.3,"gnp",directed=T)
V(gg)$group<-7
assortativity(gg, as.numeric(V(gg)$group)+rnorm(1,0,.001))
[1] 1

 A: 
However, for my dataset, I have a network for a particular situation where all the attributes are identical. Theoretically, this should be high homophily/assortativity.

Assortativity is the Pearson correlation between values at the endpoints of edges. Note that Pearson correlation is normalized. If all values are the same, the expression leads to 0/0, which on a computer leads to NaN.

That said, I notice that you are using an attribute named "group". Is this representing the index of a group in some clustering? Are you trying to compute the tendency of vertices to connect to others within the same group? If so, you should be using assortativity_nominal() instead of assortativity().
It makes no sense to treat a group index as a numerical quantity. It should only be used to determine whether two vertices are within the same group. This is precisely what assortativity_nominal() does.
The R/igraph documentation needs some work, but you can read more about what these functions do here:

*

*https://igraph.org/c/html/latest/igraph-Structural.html#igraph_assortativity

*https://igraph.org/c/html/latest/igraph-Structural.html#igraph_assortativity_nominal
Note that what R/igraph version 1.4 and earlier compute is the normalized version of the measure described in the above reference pages. This is what is usually referred to as "assortativity" in the literature.
