按照《R语言实战》中的峰度和偏度函数:
mystats<-function(x,na.omi=FALSE){
if (na.omit)
x<-x[!is.na(x)]
m<-mean(x)
n<-length(x)
s<-sd(x)
skew<-sum((x-m)^3/s^3)/n
kurt<-sum((x-m)^4/s^4)/n-3
return(c(n=n,mean=n,stdev=s,skew=skew,kurtosis=kurt))
}
调用
sapply(data, mystats)
为什么总是报错:Error in if (na.omit) x <- x[!is.na(x)] :
argument is not interpretable as logical
谢谢!
|