R语言中实现统计基因的缺失率

 

001、

gene1 <- c(0,0,1,0)
gene2 <- c(1,1,0,1)
gene3 <- c(0,1,0,1)

dat <- data.frame(gene1, gene2, gene3)    ## 生成测试数据, 0表示基因缺失, 1表示基因存在

rate_0 <- function(x)                     ## 生成统计函数
{
  count = sum(x == 0)
  return(count/length(x))
}
dat
apply(dat, 2, rate_0)          ## 借助apply函数输出所有基因的缺失率

 

posted @ 2023-02-26 17:14  小鲨鱼2018  阅读(40)  评论(0编辑  收藏  举报