[R] How to transfer the variable into function in this code?

xingxing zixingwang at hotmail.com
Wed Oct 12 22:28:09 CEST 2011


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.



More information about the R-help mailing list