作者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