【发布时间】:2011-11-30 22:02:31
【问题描述】:
我正在对文件/表中的两列运行 cor.test。
tmp <- read.table(files_to_test[i], header=TRUE, sep="\t")
## Obtain Columns To Compare ##
colA <-tmp[compareA]
colB <-tmp[compareB]
# sctr = 'spearman cor.test result'
sctr <- cor.test(colA, colB, alternative="two.sided", method="spearman")
但我遇到了这个令人困惑的错误......
Error in cor.test.default(colA, colB, alternative = "two.sided", method = "spearman") :
'x' must be a numeric vector
列中的值是数字,但是
is.numeric(colA) = FALSE
class (colA) = data.frame
我错过了什么?
【问题讨论】:
-
str(colA)和str(colB)的结果是什么。我猜数据是作为因子或字符数据读入的,可能是因为您正在读取的数据中存在错误字符。 -
@Chase:我赞成您的评论,但后来意识到这不是问题(请参阅下面的两个答案)。事后看来,我认为这有点误导,但我无法删除我的赞成票......
-
@Ben 和@Chase:给
str结果的建议是好的。 (我投了第二个赞成票)。