0

I have an edge list of person-to-person data

PersonTo,PersonFrom
   P1,P2
   P3,P1
   P4,P6
   P6,P1

I want to convert this in adjacency matrix format. I have tried the code given below but it shows output on R screen. How can i save this output in csv format?

rm(list=ls())
getwd()
library(igraph)
datafile <- "C:\\Users\\user\\desktop\\dd.csv"
edges <- read.csv(datafile)
head(edges)
as.matrix(get.adjacency(graph.data.frame(edges)))
user12
  • 761
  • 8
  • 24
  • Have you tried `write.csv`? The output may be what you want, though you might want to set `row.names = FALSE` – David Robinson May 18 '17 at 19:03
  • as.matrix(get.adjacency(graph.data.frame(edges))) write.csv(edges, file = "C:\\Users\\user\Desktop\\ddout.csv", row.names = FALSE) yes it shows the matrix input file but didnt shows the column names at left side – user12 May 18 '17 at 19:15
  • 1
    No, I mean `write.csv(as.matrix(get.adjacency(graph.data.frame(edges))), file = "C:\\Users\\user\Desktop\\ddout.csv", row.names = FALSE)` – David Robinson May 18 '17 at 19:16
  • This command shows this output Error in file(file, ifelse(append, "a", "w")) : cannot open the connection In addition: Warning message: In file(file, ifelse(append, "a", "w")) : cannot open file 'C:\Users\sakih_000\Desktop\ddout.csv': Permission denied – user12 May 18 '17 at 19:19
  • then write it to a different file, like just "thisfile.csv", which puts it in your working directory. – David Robinson May 18 '17 at 19:22
  • 'm <- as.matrix(get.adjacency(graph.data.frame(edges))) write.csv(m, file = "C:\\Users\\sakih_000\\Desktop\\ddout1t.csv")'"Solved by removing row.names = FALSE) – user12 May 18 '17 at 19:32

0 Answers0