请用Functions to manipulate Excel 2007 workbooks以后的版本。
如果用Functions to manipulate Excel 2007 workbooks以前的版本就会出现NA结果。请看以下运行结果.
x y
1 1 59.17
2 2 126.83
3 3 62.76
4 4 173.04
5 5 131.80
6 6 130.10
7 7 205.60
8 8 123.58
9 9 267.85
10 10 275.28
11 11 211.10
12 12 148.32
13 NA NA
14 NA NA
15 NA NA
16 NA NA
17 NA NA
> library(xlsx)
> setwd("E:\\RWJ")
> pe<-read.xlsx("test2.xlsx",1)
> pe
x y
1 1 59.17
2 2 126.83
3 3 62.76
4 4 173.04
5 5 131.80
6 6 130.10
7 7 205.60
8 8 123.58
9 9 267.85
10 10 275.28
11 11 211.10
12 12 148.32
13 NA NA
14 NA NA
15 NA NA
16 NA NA
17 NA NA
> R<-cor(pe)
> R
x y
x 1 NA
y NA 1
> library(xlsx)
> setwd("E:\\RWJ")
> pe<-read.xlsx("test.xlsx",1)
> pe
x y
1 1 59.17
2 2 126.83
3 3 62.76
4 4 173.04
5 5 131.80
6 6 130.10
7 7 205.60
8 8 123.58
9 9 267.85
10 10 275.28
11 11 211.10
12 12 148.32
> R<-cor(pe)
> R
x y
x 1.0000000 0.6771987
y 0.6771987 1.0000000
>