R 資料匯入與匯出

2021-07-25 22:33:31 字數 1152 閱讀 4682

> getwd() #讀取當前工作目錄

[1] "d:/r_edu"

> setwd("c:/users/steve/desktop")

> #修改工作目錄

>

(1)read.table()匯入普通文字檔案
read.table(file,header=false,sep=",",

fileencoding="utf-8",stringsasfactors=false)

(2)read.csv()匯入.csv檔案
data1 <- read.csv("1.csv", fileencoding="utf-8", stringsasfactors=false)
(3)read.xlsx()匯入excel檔案
install.packages("xlsx")

library(xlsx)

read.xlsx(file,1) #第二個引數表示sheet1,可用?read.xlsx()檢視引數設定

nu<- c(7, 9);

ch<- c('a', 'b');

st<- c("好", "壞");

f <- data.frame(nu, ch, st, stringsasfactors = false);

#啥都沒去除

write.table(f, file='f1.csv', sep=',', fileencoding = "utf-8")

#去除行號

write.table(f, file='f2.csv', sep=',', fileencoding = "utf-8", row.names=false)

#去除行號、列名

write.table(f, file='f3.csv', sep=',', fileencoding = "utf-8", row.names=false, col.names=false)

#去除行號、列名、引號

write.table(f, file='f4.csv', sep=',', fileencoding = "utf-8", quote = false, row.names=false, col.names=false)

備註:

資料匯出與匯入

1.整庫匯出與匯入 匯出命令 exp system root full y 新增引數 full y 就是整庫匯出,root為system使用者的密碼 執行命令後會在當前目錄下生成乙個叫 expdat.dmp,此檔案為備份檔案。如果想指定備份檔案的名稱,則新增 file 引數即可 exp system...

R檔案匯入匯出與快捷鍵

用rstudio的話,在tools裡的global options裡packages可以設定預設的映象點 讀取檔案 a read.table e bs test.txt sep t a read.table e 10x06 r 00000.txt sep quote encoding utf 8 讀...

mysql 資料匯入與匯出

在dos的 mysql安裝目錄 bin 目錄下用下面命令 mysql u username p databasename use database name 然後使用下面這個命令 mysql source 111.sql 當預設111.sql路徑時,必須放在mysql裡的bin裡 成功匯入!yeah...