[程式] R 語言 讀檔(XLS 或是 TXT檔)的問題

看板NCKU-StaGS01作者 (李崩子)時間13年前 (2011/05/18 11:35), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
※ [本文轉錄自 Statistics 看板 #1DqEy14W ] 作者: 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

05/16 19:24,
na=""
05/16 19:24

05/16 21:00,
用 read.delim 試試看
05/16 21:00

05/16 21:51,
個人的經驗是用read.csv(檔案也存成CSV檔)就很少出錯...
05/16 21:51

05/17 00:37,
試試 data <- read.table("C:/mix.txt", sep="分隔符號")
05/17 00:37

05/17 14:43,
讀xls檔要用到ODBC函數比較不推 最好還是用csv格式
05/17 14:43

05/18 00:04,
試 read.table("mix.txt",na.strings="NA",sep="\t")
05/18 00:04

05/18 10:26,
data <- read.table("mix.csv", sep=",")
05/18 10:26

05/18 10:26,
錯誤在scan(file, what, nmax, sep, dec, quote, skip,
05/18 10:26

05/18 10:27,
第 1 列沒有 26 個元素
05/18 10:27

05/18 10:27,
此外: Warning messages:
05/18 10:27

05/18 10:27,
1: Reached total allocation of 1535Mb: see help(memor
05/18 10:27

05/18 10:28,
2: Reached total allocation of 1535Mb: see help(memor
05/18 10:28
sqrt1089:轉錄至看板 NCKU-StaGS00 05/18 11:34 -- -- ▂▂ ▂▂▂ ▂▄▅▅▄▆█ _█◣ ◢ (●) ◣/\\ 丫 │◥  ̄◤ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.116.215.174
文章代碼(AID): #1DqpvsMn (NCKU-StaGS01)