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))
posted @ 2022-06-17 10:43  橙子牛奶糖  阅读(2509)  评论(0编辑  收藏  举报