R相关和两个数据集之间的相关系数

R相关和两个数据集之间的相关系数,r,correlation,R,Correlation,我有两个数据集,一个显示6个国家的入学率,另一个显示每个国家的GDP。 我想计算每个国家的入学率和GDP之间的相关系数。 我可以在以下网址查找问题: 但我对两个数据集的范围(数据集的行数和列数)有问题 Schoolenrollemnt数据集: gdp数据集: X轴的值必须为年(2000200420082012),y轴的值必须为注册类型。。。 对于每个国家,我需要单独的图表,,,,“注释处的图表链接” 代码不是那么正确,但这是我的开始: library(lattice)

我有两个数据集,一个显示6个国家的入学率,另一个显示每个国家的GDP。 我想计算每个国家的入学率和GDP之间的相关系数。 我可以在以下网址查找问题:

但我对两个数据集的范围(数据集的行数和列数)有问题

Schoolenrollemnt数据集:

gdp数据集:

X轴的值必须为年(2000200420082012),y轴的值必须为注册类型。。。 对于每个国家,我需要单独的图表,,,,“注释处的图表链接”

代码不是那么正确,但这是我的开始:

    library(lattice)
        xtest<-read.csv(file.choose(), header=T, sep=",")
ytest<-read.csv(file.choose(), header=F, sep=",")
xvalues<-as.matrix(xtest)
yvalues<-as.matrix(ytest)
corvalue<-cor(xvalues,yvalues)
image(x=seq(dim(xvalues)[2]), y=seq(dim(yvalues)[2]), z=corvalue, xlab="x column", ylab="y column")
text(expand.grid(x=seq(dim(xvalues)[2]), y=seq(dim(yvalues)[2])), labels=round(c(corvalue),2))
对于ScoolenRolling,我取数据的子集ytest:

0   2.39124 4.3563  23.68581    24.80515401
99.78652    116.7763    121.0558    112.08  117.3767
0   31.8468 48.04706    60.04706    73.48619
0.82459 1.41838 3.00913 6.474124923 11.42145
有什么更好的输出建议吗? 注释中的输出结果:

我使用以下代码:

xtest<-read.csv(file.choose(), header=T, sep=",")
ytest<-read.csv(file.choose(), header=F, sep=",")
xvalues<-as.matrix(xtest)
yvalues<-as.matrix(ytest)
corvalue<-cor(xvalues,yvalues)
image(x=seq(dim(xvalues)[2]), y=seq(dim(yvalues)[2]), z=corvalue, xlab="x column", ylab="y column")
text(expand.grid(x=seq(dim(xvalues)[2]), y=seq(dim(yvalues)[2])), labels=round(c(corvalue),2))
xtest:

Comoros Comoros Comoros Comoros
201899884   201899884   201899884   201899884
362420484   362420484   362420484   362420484
4880000000  4880000000  4880000000  4880000000
6800000000  6800000000  6800000000  6800000000

我想我想要达到类似于此图的效果:我想你必须澄清这两个csv文件是什么,或者给我们一个玩具数据集示例。@RandyLai,关于这个问题,有两个数据集链接。。。欢迎来到SO!通过使您的数据集“可复制粘贴”,例如使用
dput
,使人们能够轻松地帮助您。您还应该向我们展示您尝试过的代码,并解释为什么它不能满足您的需求。因此,这不是要求从头开始编写所有代码的地方。请阅读。@Henrik,谢谢你建议如何发布我的问题。。我编辑了这个问题,希望它现在更清楚
0   2.39124 4.3563  23.68581    24.80515401
99.78652    116.7763    121.0558    112.08  117.3767
0   31.8468 48.04706    60.04706    73.48619
0.82459 1.41838 3.00913 6.474124923 11.42145
xtest<-read.csv(file.choose(), header=T, sep=",")
ytest<-read.csv(file.choose(), header=F, sep=",")
xvalues<-as.matrix(xtest)
yvalues<-as.matrix(ytest)
corvalue<-cor(xvalues,yvalues)
image(x=seq(dim(xvalues)[2]), y=seq(dim(yvalues)[2]), z=corvalue, xlab="x column", ylab="y column")
text(expand.grid(x=seq(dim(xvalues)[2]), y=seq(dim(yvalues)[2])), labels=round(c(corvalue),2))
0   2.39124 4.3563  23.68581    24.80515401
99.78652    116.7763    121.0558    112.08  117.3767
0   31.8468 48.04706    60.04706    73.48619
0.82459 1.41838 3.00913 6.474124923 11.42145
Comoros Comoros Comoros Comoros
201899884   201899884   201899884   201899884
362420484   362420484   362420484   362420484
4880000000  4880000000  4880000000  4880000000
6800000000  6800000000  6800000000  6800000000