【发布时间】:2021-04-01 21:47:14
【问题描述】:
我想找到这些变量之间的 Spearman 等级相关性 rho 值。
V1 V2 V3 V4
A SUV Yes Good
A SUV No Good
B SUV No Good
B SUV Yes Satisfactory
C car Yes Excellent
C SUV No Poor
D SUV Yes Poor
D van Yes Satisfactory
E car No Excellent
corr <- cor.test(x=df$V2, y=df$V3, method = "spearman")
corr
在传递代码时,我收到以下错误(错误 1)
Error in cor.test.default(x = df$V2, y = df$V3, method = "spearman") :
'x' must be a numeric vector
我尝试了什么?
基于堆栈溢出中的讨论:How to convert a data frame column to numeric type?
transform(df, V2 = as.numeric(V2))
但是,在传递上述代码时,我收到以下错误(错误 2),并且即使在转换后仍然出现错误 1 消息。
Warning message:
In eval(substitute(list(...)), `_data`, parent.frame()) :
NAs introduced by coercion
【问题讨论】:
标签: r correlation na