R报错:Error in quantile.default(x, probs = p) : missing values and NaN's not allowed if 'na.rm' is FALSE
执行以下代码时出现的报错:
.calcFactorQuantile <- function (data, lib.size, p=0.75)
#Generalized version of upper-quartile normalization
{
f <- rep_len(1,ncol(data))
for (j in seq_len(ncol(data))) f[j] <- quantile(data[,j], probs=p)
if(min(f)==0) warning("One or more quantiles are zero")
f / lib.size
}
f75 <- suppressWarnings(.calcFactorQuantile(data=x, lib.size=lib.size, p=0.75))
解决方案:在quantile
函数加上na.rm=TRUE
参数
.calcFactorQuantile <- function (data, lib.size, p=0.75)
#Generalized version of upper-quartile normalization
{
f <- rep_len(1,ncol(data))
for (j in seq_len(ncol(data))) f[j] <- quantile(data[,j], probs=p,na.rm=TRUE)
if(min(f)==0) warning("One or more quantiles are zero")
f / lib.size
}
f75 <- suppressWarnings(.calcFactorQuantile(data=x, lib.size=lib.size, p=0.75))
本文来自博客园,作者:橙子牛奶糖(陈文燕),转载请注明原文链接:https://www.cnblogs.com/chenwenyan/p/16384901.html