as shown in the code, four variables input: diff_expr,diff_coex, klist, Pop_size, are included in the function. However, within the function, another variable "vector" is utilized in some subfunction. How they get its value?
thx get_quantiles <-function(diff_expr,diff_coex,klist,pop_size){ ##### The function to get the "node_score_term" and "edge_score_term" of a sub-network denoted by "vector" my.fun<-function(vector){ return(diff_coex[vector[1],vector[2]]) } # "vector" is a binary vector with length equal to the size of the whole network. # An element of value "1" indicates the inclusion of that gene in the selected sub-network. node_edge<-function(vector){ selected_subset<-which(vector==1) n<-length(selected_subset) node_score<-sum(diff_expr[selected_subset])/sqrt(n) edges<-combn(selected_subset,2) edge_score<-sum(apply(edges,2,my.fun))/sqrt(choose(n,2)) return(c(node_score,edge_score)) } } -- View this message in context: http://r.789695.n4.nabble.com/How-to-transfer-the-variable-into-function-in-this-code-tp3899576p3899576.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help@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.