翻翻过去那场雪
1.R数据的保存与加载可通过save()函数保存为.Rdata文件,通过load()函数将数据加载到R中。[ruby] view plain copy> a <- 1:10 > save(a,file='d://data//dumData.Rdata') > rm(a) #将对象a从R中删除 > load('d://data//dumData.Rdata') > print(a) [1] 1 2 3 4 5 6 7 8 9 10 2.CSV文件的导入与导出下面创建df1的数据框,通过函数write.csv()保存为一个.csv文件,然后通过read.csv()将df1加载到数据框df2中。[ruby] view plain copy> var1 <- 1:5 > var2 <- (1:5)/10 > var3 <- c("R and","Data Mining","Examples","Case","Studies") > df1 <- data.frame(var1,var2,var3) > names(df1) <- c("VariableInt","VariableReal","VariableChar") > write.csv(df1,"d://data//dummmyData.csv",row.names = FALSE) > df2 <- read.csv("d://data//dummmyData.csv") > print(df2) VariableInt VariableReal VariableChar 1 1 0.1 R and 2 2 0.2 Data Mining 3 3 0.3 Examples 4 4 0.4 Case 5 5 0.5 Studies 3.通过ODBC导入与导出数据RODBC提供了ODBC数据库的连接。3.1从数据库中读取数据odbcConnect()建立一个数据库连接,sqlQuery()向数据库发送一个SQL查询,odbcClose()关闭数据库连接。[ruby] view plain copylibrary(RODBC) connection <- odbcConnect(dsn="servername",uid="userid",pwd="******") query <- "SELECT * FROM lib.table WHERE ..." # or read query from file # query <- readChar("data/myQuery.sql", nchars=99999) myData <- sqlQuery(connection, query, errors = TRUE) odbcClose(connection) sqlSave()和sqlUpdate()用于写入或更新一个ODBC数据库表。3.2从Excel文件中导入与导出数据[ruby] view plain copylibrary("RODBC") conn<-odbcConnectExcel("D:/data/Amtrak.xls") Amtrak<-sqlFetch(conn,"Data") close(conn) 本回答由网友推荐