作者sqrt1089 (李崩子)
看板Statistics
標題[程式] R 語言 讀檔(XLS 或是 TXT檔)的問題
時間Mon May 16 17:31:41 2011
------------------------------------------------------------------------
[軟體程式類別]:
R
[程式問題]:
資料處理、迴歸、敘述統計、都有
[軟體熟悉度]:
請把以下不需要的部份刪除
新手(不到1個月)
根據不同熟悉度
板上高手可以給予你不同指導
新手或許需要的還是語法的熟悉
而其他部分則可能往往是盲點上的點破
[問題敘述]:
主要工作是填EXCEL裡面的miss value,所以我想最首先得工作就是讀檔問題
爬過讀檔的文章#199_LMya(爬過很多篇)也按照裡面的方法去執行
以下是我按照蒐尋到文章裡的方法執行出來的結果,有變更現行目錄,跟把要讀的
TXT檔或是excel檔也放在C槽一起TRY過了,以下是程式碼,要讀的檔案為叫作mix.txt(
mix.xls),裡面是一個N*M的矩陣,有英文有數字跟缺失值,例如:
A 1 2 3 ... 8
B 2 4 9 ... 6
C 3 1 ... 4
D 2 0 ... 1
之類的就是有空白的,
[程式範例]:
> work1<-matrix(scan("mix.txt"))
錯誤在scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, :
scan() 需要 'a real',而不是 'YORF'
> work1<-matrix(scan("mix.xls"))
錯誤在scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, :
scan() 需要 'a real',而不是 '俵ꄿ
> data <- read.table("C:/mix.txt")
錯誤在scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, :
第 1 列沒有 30 個元素
> d<-read.table("mix.txt")
錯誤在scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, :
第 1 列沒有 30 個元素
> data1 <- read.xls("mix.xls")
錯誤在.Call("ReadXls", file, colNames, sheet, type, from, rowNames, :
Incorrect number of arguments (11), expecting 10 for 'ReadXls'
>
都不能讀取= =,但是如果是一個完整矩陣就能讀取,所以想問問要怎麼讀取一個有
空白值的txt檔或是exl檔
文長抱歉
-----------------------------------------------------------------------------
--
--
▂▂ ▂▂▂
▂▄▅▅▄▆█ _█◣
◢ (●) ◣/\\
丫 │◥  ̄◤
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.116.215.174
1F:→ clickhere:na="" 05/16 19:24
2F:→ gsuper:用 read.delim 試試看 05/16 21:00
3F:→ diplazium:個人的經驗是用read.csv(檔案也存成CSV檔)就很少出錯... 05/16 21:51
4F:推 uper:試試 data <- read.table("C:/mix.txt", sep="分隔符號") 05/17 00:37
5F:→ onlyyou2:讀xls檔要用到ODBC函數比較不推 最好還是用csv格式 05/17 14:43
6F:→ c0935471010:試 read.table("mix.txt",na.strings="NA",sep="\t") 05/18 00:04
7F:→ sqrt1089: data <- read.table("mix.csv", sep=",") 05/18 10:26
8F:→ sqrt1089:錯誤在scan(file, what, nmax, sep, dec, quote, skip, 05/18 10:26
9F:→ sqrt1089: 第 1 列沒有 26 個元素 05/18 10:27
10F:→ sqrt1089:此外: Warning messages: 05/18 10:27
11F:→ sqrt1089:1: Reached total allocation of 1535Mb: see help(memor 05/18 10:27
12F:→ sqrt1089:2: Reached total allocation of 1535Mb: see help(memor 05/18 10:28
※ sqrt1089:轉錄至看板 NCKU-StaGS00 05/18 11:34
※ sqrt1089:轉錄至看板 NCKU-StaGS01 05/18 11:35
13F:→ sqrt1089:抱歉轉其他地方,因為這樣應該最快處理,搞了2個禮拜還在 05/18 11:36
14F:→ sqrt1089:原地踏步 05/18 11:36