Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201867

write different size vector into file row by row

$
0
0

I am the beginner of R language. I want to write different size vector into csv. Here is code:

library(igraph)
library(DirectedClustering)
my_list = readLines("F://RR//listtest.csv")
eigen <-c()
for(i in 1:length(my_list))
{

  my_data <- read.csv(my_list[i],head=TRUE, row.names =1 )
  my_matrix <-as.matrix(my_data)
  g1 <- graph_from_adjacency_matrix(my_matrix, weighted=TRUE,diag = FALSE)
  e1 <- eigen_centrality(g1,directed = TRUE)
  eigen[[i]] <-e1[["vector"]]  
}
df = data.frame(eigenvalue,eigen)
df
write.csv(df, "F://RR//outtest.csv")

The first question is due to different size of vector (the max is 14), the data.frame can not be used. The second question is when i use the same size of vector to write into some csv file,it will display like

 - Vec1 Vec2 Vec3
1. 2.5  3.5  4.5
2. 1.8  1.6  1.4
3. 1.3  5.8  9.9

but i wanna it display row by row, something like:

  • 1 2.5
  • 2 3.5
  • 3 4.5
  • 4 1.8
  • 5 1.6
  • 6 1.4
  • 7 1.3
  • 8 5.8
  • 9 9.9

I really need your help, thanks lot.


Viewing all articles
Browse latest Browse all 201867

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>