R讀寫檔案略記

2gua發表於2013-05-29

R讀寫檔案,我用得最多的就是csv格式檔案。

讀檔案舉例如下(D:\temp\1.csv):
enter image description here

示例程式碼如下:

> myData = read.table(file = "d://temp/1.csv", sep = ",")
> myData
  V1 V2 V3 V4 V5
1  1  2  3  4  5
2  6  7  8  9 10
3 11 12 13 14 15
> mode(myData)
[1] "list"
> length(myData)
[1] 5
> myData$V1
[1]  1  6 11
>

或者直接:

myData = read.csv(file = "d://temp/1.csv")

寫檔案示例程式碼:

write.table(list("A", "B", "C", "D", "E"), file = "d://temp/1.csv", append = TRUE, quote = FALSE, sep = ",", row.names = FALSE, col.names = FALSE)

結果:
enter image description here

時間煮雨,去聽吧,有點憂傷,跟今天的心境一樣......

#stats# enter image description here