R Markdown

http://rmarkdown.rstudio.com. Knit includes both content as well as the output

U09: 檔案資料輸入與輸出

檔案資料輸入與輸出

設定工作目錄

rm( list = ls() )
ls()
## character(0)
mywd <- "H:/DataR"

setwd( mywd )

getwd( )
## [1] "H:/DataR"

資料儲存 – dump, source

儲存物件的名稱與其值(內容)

x <- 1:10
y <- matrix( 1:6, nrow = 2, ncol = 3 )

x
##  [1]  1  2  3  4  5  6  7  8  9 10
y
##      [,1] [,2] [,3]
## [1,]    1    3    5
## [2,]    2    4    6
ls()
## [1] "mywd" "x"    "y"

dump some data/command into a file

ls()
## [1] "mywd" "x"    "y"
dump( c("x", "y"), file = "mydump.txt")
ls()
## [1] "mywd" "x"    "y"

remove the variables

rm(x); rm(y)
ls()
## [1] "mywd"

read the content

source( file = "mydump.txt" )
ls()
## [1] "mywd" "x"    "y"

資料儲存 – dput, dget

儲存物件的值(內容)

x <- 1:10
y <- matrix( 1:6, nrow = 2, ncol = 3 )

x
##  [1]  1  2  3  4  5  6  7  8  9 10
y
##      [,1] [,2] [,3]
## [1,]    1    3    5
## [2,]    2    4    6
dput( y, file = "mydput.txt" )