N******n 发帖数: 3003 | 1 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))
}
}
就问一下, 在function 里面,有个变量,vector, 他是怎样传递进去的? 程序运行
时好的,
包子答谢 | M*P 发帖数: 6456 | 2 ?apply
【在 N******n 的大作中提到】 : 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.
| N******n 发帖数: 3003 | 3
就是 vector 是怎样从外面到里面去的? 好像input list里面没有它
【在 M*P 的大作中提到】 : ?apply
| e*****t 发帖数: 642 | | N******n 发帖数: 3003 | 5
你是说, global variable 吗? 好像R 里面不常见吧
【在 e*****t 的大作中提到】 : vector在function外定义的。
|
|