Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我想使用cor()函数,但输出显示';y';必须是数字。问题是,它是数字的_R_Correlation_Numeric - Fatal编程技术网

我想使用cor()函数,但输出显示';y';必须是数字。问题是,它是数字的

我想使用cor()函数,但输出显示';y';必须是数字。问题是,它是数字的,r,correlation,numeric,R,Correlation,Numeric,我正在从xlsx文件中读取数据。我的读取代码是这样开始的: ecommerce<-read.xlsx("C:\\Users\\Thomas Rhee\\Documents\\GGU\\GGU Fall 2018\\Tools for Business Analytics\\Final Project\\ecommerce.xlsx", sheet = "data", startRow = 1, colNames = TRUE, col = c(1,2,3,4,5,6,7,8)); atta

我正在从xlsx文件中读取数据。我的读取代码是这样开始的:

ecommerce<-read.xlsx("C:\\Users\\Thomas Rhee\\Documents\\GGU\\GGU Fall 2018\\Tools for Business Analytics\\Final Project\\ecommerce.xlsx", sheet = "data", startRow = 1, colNames = TRUE, col = c(1,2,3,4,5,6,7,8));
attach(ecommerce)
names(ecommerce)
price
<chr>
329.98  
324.83999999999997  
324.83  
350 
308 
310
我又检查了一遍,它成功了。我尝试键入以下内容并获得此输出:

cor(rank, price) 
cor(等级、价格)中的错误:“y”必须是数字


我迷路了。我也是这方面的初学者,所以我愿意接受这里的建议。请帮我把它说清楚。

这是一个很好的例子,说明了为什么不应该使用
附件

d <- data.frame(x = 1:3)
attach(d)
x ## now available because of attach
# [1] 1 2 3

d$x <- LETTERS[1:3]
x ## however this still refers to the original values of d$x
# [1] 1 2 3
d$x
# [1] "A" "B" "C"

从技术上讲,您可以在更改后再次重新附加
电子商务
,但由于这些问题,我强烈建议您不要使用
附加

d <- data.frame(x = 1:3)
attach(d)
x ## now available because of attach
# [1] 1 2 3

d$x <- LETTERS[1:3]
x ## however this still refers to the original values of d$x
# [1] 1 2 3
d$x
# [1] "A" "B" "C"
cor(ecommerce$rank, ecommerce$price)