R和cor功能

时间:2015-02-12 19:44:55

标签: r

我已在R REPL中编写此代码

content <- read.csv("[001.csv][1]", header=TRUE)
head(content, n=5L)
cc <- subset(content, !is.na(sulfate) & !is.na(nitrate))
head(cc, n = 5L)
cor <- cor(cc[2], cc[3])
print(cor)

head(content, n=5L)

#         Date sulfate nitrate ID 
#1  2003-01-01      NA      NA  1 
#2  2003-01-02      NA      NA  1 
#3  2003-01-03      NA      NA  1 
#4  2003-01-04      NA      NA  1 
#5  2003-01-05      NA      NA  1 

head(cc, n=5L)

#          Date sulfate nitrate ID             
#279 2003-10-06    7.21   0.651  1             
#285 2003-10-12    5.99   0.428  1             
#291 2003-10-18    4.68   1.040  1             
#297 2003-10-24    3.47   0.363  1             
#303 2003-10-30    2.42   0.507  1

print(cor)

#           nitrate
#sulfate -0.2225526

我想知道为什么它会说nitrate sulfate -0.2225526而不仅仅是-0.2225526

在我看来,cor函数无法理解行和标题之间的区别?还是别的......

我预期的输出只是-0.2225526而不是nitrate sulfate -0.2225526

0 个答案:

没有答案