R 函数构造练习

name <- rownames(rt_expr)   #基因名

immune <- function(genename){
    y <- as.numeric(rt_expr)    #单一基因的表达量表格
    do.call(rbind,lapply(colnames(rt),function(x){    #rt列明与rt_expr的行名相同 
        test <- cor.test(rt[,x],y,type="spearman")
        cor <- test$estimate
        p.value <- test$p.value
        data.frame(gene=genename,symbol=x,correlation=cor,pvalue=p.value)
        }))
    }

data <- immune(name)


函数的参数的传入也可以多个,以及固定参数如下: 
compute <- function(x,y,d=2){
    ....
    }
此条目发表在R分类目录。将固定链接加入收藏夹。

R 函数构造练习》有1条回应

  1. 周捷说:

    感谢博主分享

发表评论

电子邮件地址不会被公开。 必填项已用*标注

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax

Protected with IP Blacklist CloudIP Blacklist Cloud