Question

I used igraph package to detect communities. When I used membership(community) function, the result is:

    1    2    3    4    5    6    7   13   17   18   19   20   22   23   24   25
   12    9    1   10   12    6   12   16    1   11    6    6    3   13   16    1
   29   30   31   33   34   37   38   39   40   41   42   43   44   45   46   47
    9    5   11   14   13    6   13   11   12   13    1   16   11    6   12    7
    ...

The first line is node ID and the second line is its corresponding community ID. Suppose the name of the above result is X. I used Y=data.frame(X). The result is:

  community
1   12
2    9
3    1
4   10
5   12
6    6
7   12
13  16
...

I want to use the first column (1,2,3,...), for instance, Y[13,]=16. But in this case, it is Y[8,]=16. How to do this?

This question may be very simple. But I do not know how to google it. Thanks.

Was it helpful?

Solution

Function as.data.frame() converts a named vector to a data frame, where the names of the vector elements are used as row names.

In other words, use a construct like rownames(Y)[8] to access the first column (or the row names, actually).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top