#数据库输入 #ODBC接口 library(RODBC) myconn<- odbcConnect("test",uid="root",pwd="123456") crimedat<-sqlFetch(myconn,Crime) pundat<-sqlQuery(myconn,"select * from zt_bug") colse(myconn) #文件输入 --- 文本文件 #mydata<-read.table(file,header=logical_value,sep="delimiter",row.names="name") #datainput文件内容 #SID,NAME,AGE,GRADE,SCORE #1,test1,35,CLASS1,88 #2,test2,30,CLASS2,78 #3,test3,10,CLASS3,98 grades<-read.table("/home/caojj/temp/datainput",header=TRUE,sep=",",row.names="SID") grades #注意:文本文件需要保留一空行,否则会有告警 #文件输入 --- excel #install.packages("RODBC") #library(RODBC) #channel<-odbcConnectExcel("mydata.xls") #mydataframe<-sqlFetch(channel,"mysheet") #odbcClose(channel) library(xlsx) workbook<-"/home/caojj/temp/export.xls" mydataframe<-read.xlsx(workbook,1) mydataframe #文件输入 --- Stata library(foreign) mydataframe<-read.dta("mydata.dta") #键盘输入 mydata<-data.frame(age=numeric(0),gender=character(0),weight=numeric(0)) mydata <- edit(mydata) #等同于: fix(mydata) mydata