Hi, As a beginner in R, I need some help on a programming problem which, I guess, will seem trivial to you: I am doing some Network analysis in which I need to calculate some metrics for all the weeks I have (each week the network evolves in terms of number of nodes etc...) For exemple, I need to calculate the degrees of the nodes each weak, and to repeat it in a loop for all the weeks ( for 265 weeks). So for each weak, I want to write a vector containing the degrees of every nodes ( a 1*300 vector for 300 nodes for example). At the end, I will have 265 vectors with dimensions: the number of nodes each week. In the following code I tried, the program just write one vector called indeg[i] corresponding to the last week, where I would like indeg1, indeg2,...,indeg265. Rm(list()) library(R.matlab) library(igraph) path<-("D:/adj_matrices/nonweighted_GOVSOV") setwd(path) vector.files<-paste("nonweighted_GOVSOV",1:265, ".mat",sep="") dat<-list() for(i in 1:265) { dat[[i]] <-readMat(file.path(path,vector.files[i])) adj<-do.call(rbind, dat[[i]]) g<-graph.adjacency(adj, mode=c("directed"), weighted=T) # the graph object of the network a<-length(V(g)) #the number of nodes indeg<-rep(0,a) #the vector where I want to write the degree of each node for week i indeg<-degree(g) #degree calculation for each node of the network write(indeg, "indeg[i]".txt, sep="\n") } Is there some obvious mistake in my program, or does anyone have a solution to do this? Thanks a lot , Yanis El Omari Trainee - Economic Research European Securities and Markets Authority (ESMA) 103, rue de Grenelle, 75007 Paris - France Tel: + 33 1 58 36 51 37 Email : yanis.elomari@esma.europa.eu<mailto:yanis.elomari@esma.europa.eu> [[alternative HTML version deleted]]
Hi, the thing is, you didn't really have any questions in your email. What is the problem with your code? Is it not giving the expected results? More below. On Wed, Aug 22, 2012 at 8:31 AM, Yanis El Omari <yanis.elomari at esma.europa.eu> wrote: [...]> Rm(list())What is this this supposed to do? Do you mean 'rm(list=ls())' ?> library(R.matlab) > library(igraph) > path<-("D:/adj_matrices/nonweighted_GOVSOV") > setwd(path) > vector.files<-paste("nonweighted_GOVSOV",1:265, ".mat",sep="") > dat<-list() > > for(i in 1:265) { > dat[[i]] <-readMat(file.path(path,vector.files[i])) > adj<-do.call(rbind, dat[[i]]) > g<-graph.adjacency(adj, mode=c("directed"), weighted=T) # the graph object of the network > > a<-length(V(g)) #the number of nodes > > indeg<-rep(0,a) #the vector where I want to write the degree of each node for week iThe above two lines are not needed, you can remove them.> indeg<-degree(g) #degree calculation for each node of the network > > write(indeg, "indeg[i]".txt, sep="\n")This is probably wrong, the results are written to a file named "indeg[i].txt", I think you want something like write(indeg, sprintf("indeg[%i].txt", i), sep="\n")> } > > > Is there some obvious mistake in my program, or does anyone have a solution to do this?Maybe, but what is your problem with it? (Apart from the incorrect naming of the output files.) Gabor [...] -- Gabor Csardi <csardi at rmki.kfki.hu> MTA KFKI RMKI
HELLO, I SHALL NEED A HELP. It is my official language(tongue) is French, even if I manage little in English, I shall like understanding(including) as fast as possible, that is why I asked if there is a page wiki in French, thank you in advance for your answers [[alternative HTML version deleted]]
Google est ton ami: http://lmgtfy.com/?q=R+statistiques+fran%C3%A7ais Le deuxi?me parait prometteur. Bonne chance, Rui Barradas Em 17-09-2012 20:06, Seydou Badiane escreveu:> HELLO, I SHALL NEED A HELP. It is my official language(tongue) is French, > even if I manage little in English, I shall like understanding(including) > as fast as possible, that is why I asked if there is a page wiki in French, > thank you in advance for your answers > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.