我想从数据集中获取 pvalues。我在使用 pnorm 时没有遇到任何问题,但我现在遇到了。
data(iris)
iris[,-5]<- scale(as.matrix(iris[,-5]))
# K-Means Cluster Analysis
fit <- kmeans(iris[,-5], 5) # 5 cluster solution
# get cluster means
aggregate(iris[,-5],by=list(fit$cluster),FUN=mean)
# append cluster assignment
mydata <- data.frame(iris, fit$cluster)
pval<- pnorm(iris[,-5])
Run Code Online (Sandbox Code Playgroud)
在此之后,我收到“pnorm(q, mean, sd,lower.tail, log.p) 中的错误:数学函数的非数字参数”的消息。
问题是什么?我不明白为什么会这样。
请告诉我。
您正在尝试将数据帧传递给请求数字向量的函数:
> is.numeric(iris[,-5])
[1] FALSE
> str(iris[,-5])
'data.frame': 150 obs. of 4 variables:
$ Sepal.Length: num -0.898 -1.139 -1.381 -1.501 -1.018 ...
$ Sepal.Width : num 1.0156 -0.1315 0.3273 0.0979 1.245 ...
$ Petal.Length: num -1.34 -1.34 -1.39 -1.28 -1.34 ...
$ Petal.Width : num -1.31 -1.31 -1.31 -1.31 -1.31 ...
Run Code Online (Sandbox Code Playgroud)
尝试只传递一列,例如:
pnorm(iris[,1])
Run Code Online (Sandbox Code Playgroud)