corr.test参数意味着不同的行数

时间:2015-09-11 22:07:26

标签: r

我在不同的项目中多次看到此错误,我想知道是否有办法判断哪一行导致错误一般

我的具体案例:

 http://archive.ics.uci.edu/ml/machine-learning-databases/00275/

#using the bike.csv
data<-read.csv("PATH_HERE\\Bike-Sharing-Dataset\\day.csv",header=TRUE)
require(psych)
corr.test(data) 
data<-data[,c("atemp","casual","cnt","holiday","hum","mnth","registered",
              "season","temp","weathersit","weekday","windspeed","workingday","yr")]
data[data=='']<-NA
#View(data)

require(psych)
cors<-corr.test(data)

返回错误:

Error in data.frame(lower = lower, r = r[lower.tri(r)], upper = upper,  : 
  arguments imply differing number of rows: 0, 91

2 个答案:

答案 0 :(得分:0)

它对我有用

> #using the bike.csv
> data <- read.csv("day.csv",header=TRUE)
> require(psych)
> corr.test(data) 
Error in cor(x, use = use, method = method) : 'x' must be numeric
> data <- data[,c("atemp","casual","cnt","holiday","hum","mnth","registered",
+               "season","temp","weathersit","weekday","windspeed","workingday","yr")]
> data[data==''] <- NA
> #View(data)
> 
> require(psych)
> cors <- corr.test(data)
> cors
Call:corr.test(x = data)
Correlation matrix 
           atemp casual   cnt holiday   hum  mnth registered season  temp
atemp       1.00   0.54  0.63   -0.03  0.14  0.23       0.54   0.34  0.99
casual      0.54   1.00  0.67    0.05 -0.08  0.12       0.40   0.21  0.54
cnt         0.63   0.67  1.00   -0.07 -0.10  0.28       0.95   0.41  0.63
holiday    -0.03   0.05 -0.07    1.00 -0.02  0.02      -0.11  -0.01 -0.03
hum         0.14  -0.08 -0.10   -0.02  1.00  0.22      -0.09   0.21  0.13
mnth        0.23   0.12  0.28    0.02  0.22  1.00       0.29   0.83  0.22
registered  0.54   0.40  0.95   -0.11 -0.09  0.29       1.00   0.41  0.54
season      0.34   0.21  0.41   -0.01  0.21  0.83       0.41   1.00  0.33
temp        0.99   0.54  0.63   -0.03  0.13  0.22       0.54   0.33  1.00
weathersit -0.12  -0.25 -0.30   -0.03  0.59  0.04      -0.26   0.02 -0.12
weekday    -0.01   0.06  0.07   -0.10 -0.05  0.01       0.06   0.00  0.00
windspeed  -0.18  -0.17 -0.23    0.01 -0.25 -0.21      -0.22  -0.23 -0.16
workingday  0.05  -0.52  0.06   -0.25  0.02 -0.01       0.30   0.01  0.05
yr          0.05   0.25  0.57    0.01 -0.11  0.00       0.59   0.00  0.05
           weathersit weekday windspeed workingday    yr
atemp           -0.12   -0.01     -0.18       0.05  0.05
casual          -0.25    0.06     -0.17      -0.52  0.25
cnt             -0.30    0.07     -0.23       0.06  0.57
holiday         -0.03   -0.10      0.01      -0.25  0.01
hum              0.59   -0.05     -0.25       0.02 -0.11
mnth             0.04    0.01     -0.21      -0.01  0.00
registered      -0.26    0.06     -0.22       0.30  0.59
season           0.02    0.00     -0.23       0.01  0.00
temp            -0.12    0.00     -0.16       0.05  0.05
weathersit       1.00    0.03      0.04       0.06 -0.05
weekday          0.03    1.00      0.01       0.04 -0.01
windspeed        0.04    0.01      1.00      -0.02 -0.01
workingday       0.06    0.04     -0.02       1.00  0.00
yr              -0.05   -0.01     -0.01       0.00  1.00
Sample Size 
[1] 731
Probability values (Entries above the diagonal are adjusted for multiple tests.) 
           atemp casual  cnt holiday  hum mnth registered season temp
atemp       0.00   0.00 0.00    1.00 0.01 0.00       0.00   0.00 0.00
casual      0.00   0.00 0.00    1.00 1.00 0.04       0.00   0.00 0.00
cnt         0.00   0.00 0.00    1.00 0.28 0.00       0.00   0.00 0.00
holiday     0.38   0.14 0.06    0.00 1.00 1.00       0.15   1.00 1.00
hum         0.00   0.04 0.01    0.67 0.00 0.00       0.58   0.00 0.03
mnth        0.00   0.00 0.00    0.60 0.00 0.00       0.00   0.00 0.00
registered  0.00   0.00 0.00    0.00 0.01 0.00       0.00   0.00 0.00
season      0.00   0.00 0.00    0.78 0.00 0.00       0.00   0.00 0.00
temp        0.00   0.00 0.00    0.44 0.00 0.00       0.00   0.00 0.00
weathersit  0.00   0.00 0.00    0.35 0.00 0.24       0.00   0.60 0.00
weekday     0.84   0.11 0.07    0.01 0.16 0.80       0.12   0.93 1.00
windspeed   0.00   0.00 0.00    0.87 0.00 0.00       0.00   0.00 0.00
workingday  0.16   0.00 0.10    0.00 0.51 0.87       0.00   0.74 0.15
yr          0.21   0.00 0.00    0.83 0.00 0.96       0.00   0.96 0.20
           weathersit weekday windspeed workingday   yr
atemp            0.05    1.00      0.00       1.00 1.00
casual           0.00    1.00      0.00       0.00 0.00
cnt              0.00    1.00      0.00       1.00 0.00
holiday          1.00    0.25      1.00       0.00 1.00
hum              0.00    1.00      0.00       1.00 0.13
mnth             1.00    1.00      0.00       1.00 1.00
registered       0.00    1.00      0.00       0.00 0.00
season           1.00    1.00      0.00       1.00 1.00
temp             0.05    1.00      0.00       1.00 1.00
weathersit       0.00    1.00      1.00       1.00 1.00
weekday          0.40    0.00      1.00       1.00 1.00
windspeed        0.29    0.70      0.00       1.00 1.00
workingday       0.10    0.33      0.61       0.00 1.00
yr               0.19    0.88      0.75       0.96 0.00

 To see confidence intervals of the correlations, print with the short=FALSE option
> 

答案 1 :(得分:0)

它对我有用:::

rm(list=ls())
# http://archive.ics.uci.edu/ml/machine-learning-databases/00275/

#using the bike.csv

day <- read.csv("Bike-Sharing-Dataset//day.csv")

require(psych)

day<-day[,c("atemp","casual","cnt","holiday","hum","mnth","registered",
              "season","temp","weathersit","weekday","windspeed","workingday","yr")]

day[day=='']<-NA

require(psych)
corr.test(day) 


# corr.test(day)
# Call:corr.test(x = day)
# Correlation matrix 
# atemp casual   cnt holiday   hum  mnth registered season  temp weathersit weekday windspeed workingday    yr
# atemp       1.00   0.54  0.63   -0.03  0.14  0.23       0.54   0.34  0.99      -0.12   -0.01     -0.18       0.05  0.05
# casual      0.54   1.00  0.67    0.05 -0.08  0.12       0.40   0.21  0.54      -0.25    0.06     -0.17      -0.52  0.25
# cnt         0.63   0.67  1.00   -0.07 -0.10  0.28       0.95   0.41  0.63      -0.30    0.07     -0.23       0.06  0.57
# holiday    -0.03   0.05 -0.07    1.00 -0.02  0.02      -0.11  -0.01 -0.03      -0.03   -0.10      0.01      -0.25  0.01
# hum         0.14  -0.08 -0.10   -0.02  1.00  0.22      -0.09   0.21  0.13       0.59   -0.05     -0.25       0.02 -0.11
# mnth        0.23   0.12  0.28    0.02  0.22  1.00       0.29   0.83  0.22       0.04    0.01     -0.21      -0.01  0.00
# registered  0.54   0.40  0.95   -0.11 -0.09  0.29       1.00   0.41  0.54      -0.26    0.06     -0.22       0.30  0.59
# season      0.34   0.21  0.41   -0.01  0.21  0.83       0.41   1.00  0.33       0.02    0.00     -0.23       0.01  0.00
# temp        0.99   0.54  0.63   -0.03  0.13  0.22       0.54   0.33  1.00      -0.12    0.00     -0.16       0.05  0.05
# weathersit -0.12  -0.25 -0.30   -0.03  0.59  0.04      -0.26   0.02 -0.12       1.00    0.03      0.04       0.06 -0.05
# weekday    -0.01   0.06  0.07   -0.10 -0.05  0.01       0.06   0.00  0.00       0.03    1.00      0.01       0.04 -0.01
# windspeed  -0.18  -0.17 -0.23    0.01 -0.25 -0.21      -0.22  -0.23 -0.16       0.04    0.01      1.00      -0.02 -0.01
# workingday  0.05  -0.52  0.06   -0.25  0.02 -0.01       0.30   0.01  0.05       0.06    0.04     -0.02       1.00  0.00
# yr          0.05   0.25  0.57    0.01 -0.11  0.00       0.59   0.00  0.05      -0.05   -0.01     -0.01       0.00  1.00
# Sample Size 
# [1] 731
# Probability values (Entries above the diagonal are adjusted for multiple tests.) 
# atemp casual  cnt holiday  hum mnth registered season temp weathersit weekday windspeed workingday   yr
# atemp       0.00   0.00 0.00    1.00 0.01 0.00       0.00   0.00 0.00       0.05    1.00      0.00       1.00 1.00
# casual      0.00   0.00 0.00    1.00 1.00 0.04       0.00   0.00 0.00       0.00    1.00      0.00       0.00 0.00
# cnt         0.00   0.00 0.00    1.00 0.28 0.00       0.00   0.00 0.00       0.00    1.00      0.00       1.00 0.00
# holiday     0.38   0.14 0.06    0.00 1.00 1.00       0.15   1.00 1.00       1.00    0.25      1.00       0.00 1.00
# hum         0.00   0.04 0.01    0.67 0.00 0.00       0.58   0.00 0.03       0.00    1.00      0.00       1.00 0.13
# mnth        0.00   0.00 0.00    0.60 0.00 0.00       0.00   0.00 0.00       1.00    1.00      0.00       1.00 1.00
# registered  0.00   0.00 0.00    0.00 0.01 0.00       0.00   0.00 0.00       0.00    1.00      0.00       0.00 0.00
# season      0.00   0.00 0.00    0.78 0.00 0.00       0.00   0.00 0.00       1.00    1.00      0.00       1.00 1.00
# temp        0.00   0.00 0.00    0.44 0.00 0.00       0.00   0.00 0.00       0.05    1.00      0.00       1.00 1.00
# weathersit  0.00   0.00 0.00    0.35 0.00 0.24       0.00   0.60 0.00       0.00    1.00      1.00       1.00 1.00
# weekday     0.84   0.11 0.07    0.01 0.16 0.80       0.12   0.93 1.00       0.40    0.00      1.00       1.00 1.00
# windspeed   0.00   0.00 0.00    0.87 0.00 0.00       0.00   0.00 0.00       0.29    0.70      0.00       1.00 1.00
# workingday  0.16   0.00 0.10    0.00 0.51 0.87       0.00   0.74 0.15       0.10    0.33      0.61       0.00 1.00
# yr          0.21   0.00 0.00    0.83 0.00 0.96       0.00   0.96 0.20       0.19    0.88      0.75       0.96 0.00
# 
# To see confidence intervals of the correlations, print with the short=FALSE option

欢呼声