Question: I need to change a data frame with named column and rows (NxN dimension) into an edge list.

For example the matrix in the data frame is:

```
     C1  C2  C3  C4
Ane  0   1   31  0
Jol  4   14  2   0
Ruf  3   3   11  6 
Rei  1   7    0  0

```

I want to change this to a list (like an edge list):

```
Ane-C1  0
Ane-C2  1
Ane-C3  31
Ane-C4  0
Jol-C1  4
Jol-C2  14
Jol-C3  2
Jol-C4  0
Ruf-C1  3
Ruf-C2  3
Ruf-C3  11
Ruf-C4  6
Rei-C1  1
Rei-C2  7
Rei-C3  0
Rei-C4  0

```

The other threads that I found seems to have only column names/ the data frame is not containing an adjacency matrix.

I tried to make it a graph and then get.edgelist, also tried [order(df[,1],df[1,]),,drop=FALSE] but those doesn't give what I want.
Can anyone help teach me?

Answer: 
In `base R`, replicate the rownames and column names, `paste` it, create a `data.frame` based on that along with the values of the matrix

```
data.frame(name = paste(rownames(m1)[col(m1)], colnames(m1)[row(m1)], sep="-"),
          val = c(t(m1)), stringsAsFactors = FALSE)
#     name val
#1  Ane-C1   0
#2  Ane-C2   1
#3  Ane-C3  31
#4  Ane-C4   0
#5  Jol-C1   4
#6  Jol-C2  14
#7  Jol-C3   2
#8  Jol-C4   0
#9  Ruf-C1   3
#10 Ruf-C2   3
#11 Ruf-C3  11
#12 Ruf-C4   6
#13 Rei-C1   1
#14 Rei-C2   7
#15 Rei-C3   0
#16 Rei-C4   0

```
More complete answer based on `melt` from `reshape` as pointed by user20650:

```
# add rowname to original data frame.
df$row<-rownames(df)
df1<-melt(df)
elist<-data.frame(names=paste(df1$row,df1$variable,sep="-"),value=df1$value)

```

A `data.frame` solution is like this:

```
data.frame(name = paste(rownames(df)[row(df)], colnames(df)[col(df)], sep="-"),value = c(as.matrix(df)))

```

The `melt` gives you more control. You can do something like this:

```
melt(df[1:2,3:4])

```

to convert row 1,2 and col 3,4 to edgelist.