当初装oracle数据库的时候比较混乱,账号密码没记清,最后导致odbc建不起来,没法让oracle直接和R连接起来。
所以只能先导出oracle里的数据到本地,再读进R.
导出时候用了sqlplus
sql plus 登陆 sys as sysdba -- 一定要加上 as sysdba 不然总是报错
spool d:\a.csv select ksmc || ',' || mzrq || ',' || age || ',' || gender || ',' || weekday || ',' || yearmzcnt || ',' || fee || ',' || ifholiday || ',' || hightemp || ',' || lowtemp || ',' || ifrain || ',' || winddir || ',' || windstr from tmp_tb1 spool off
-- sql plus 麻烦的是我还不知道如何复制黏贴,列太多的话,写起来比较麻烦
另外发现导出的文件里面 居然每隔几行就有一段列名说明的行,需要手动删除。我用linux删除
sed -i '/---/d' b.csv sed -i '/KSMC/d' b.csv sed -i '/select/d' b.csv sed -i '/^\s/d' b.csv sed -i '/sql/d' b.csv
最后再放入R
rm(list = ls()) setwd("D://test//") dt<-read.csv("c.csv",header = FALSE) colnames(dt)<-c("ksmc","mzrq","age","gender","weekday","yearmzcnt","fee","ifholiday","hightemp","lowtemp","ifrain") summary(dt) library(Hmisc) describe(dt)