2015-07-11 81 views
1

我嘗試導入一個帶有表示文檔號的列的大數據集。該字段包含一個前導零數爲25位的數字。 我嘗試使用read.table()導入數據,但即使在導入過程中將「字符」指定爲類時,也始終爲此特定字段獲取「1e + 19」。用read.table()導入帶有數字的長字符字段

# import elyte 
colnames<-c("patnr","name","birthday","sex","casenr","Bew","Art","docnr","date","time","none","Na","K","Cl","Ca","corCa") 
classes <- rep("character",length(colnames)) 
ELYTE <- read.table(file="ELYTE.TXT",skip=3,comment.char="",sep="|",col.names=colnames, header=FALSE, colClasses=classes) 

原始數據看起來像這樣: 0010000005 |韋伯| 19091220 | 1 | 0000337340 | 00000 | LAB | 0000010000000000000011524 | 20000127 | 084800 || 140 | 3.7 | 100 | 2.1 | 0010000005 | Weber | 19091220 | 1 | 0000337340 | 00000 | LAB | 0000010000000000000011541 | 20000127 | 080200 |||||| 0010000005 | Weber | 19091220 | 1 | 0000337340 | 00000 | LAB | 0000010000000000000011562 | 20000127 | 101800 || 140 | 4.6 | 101 | 2.2 | 0010000005 | Weber | 19091220 | 1 | 0000337340 | 00000 | LAB | 0000010000000000000011579 | 20000127 | 134500 || 138 | 4.0 || 2.2 | 0010000005 | Weber | 19091220 | 1 | 0000337340 | 00000 | LAB | 0000010000000000000011591 | 20000128 | 084200 || 138 | 3.6 | 98 | 2.1 | 0010000005 | Weber | 19091220 | 1 | 0000337340 | 00000 | LAB | 0000010000000000000011593 | 20000128 | 085900 |||||| 0010000005 | Weber | 19091220 | 1 | 0000337340 | 00000 | LAB | 0000010000000000000011653 | 20000129 | 093400 || 140 | 4.2 | 99 | 2.2 | 0010000005 | Weber | 19091220 | 1 | 0000337340 | 00000 | LAB | 0000010000000000000011717 | 20000129 | 094100 ||||||

我得到的是以下幾點:

patnr名字生日性別casenr BEW藝術docnr日期時間無鈉鉀氯鈣corCa

1 0010000005韋伯19091220 1 0000337340 00000 LAB 1E + 19 20000127 084800 140 3.7 100 2.1
2 0010000005韋伯19091220 1 0000337340 00000 LAB 1E + 19 20000127 080200
3 0010000005韋伯19091220 1 0000337340 00000 LAB 1E + 19 20000127 101800 140 4.6 101 2.2
4 0010000005韋伯19091220 1 0000337340 00000 LAB 1E + 19 20000127 134500 138 4.0 2.2
5 0010000005韋伯19091220 1 0000337340 00000 LAB 1E + 19 20000128 084200 138 3.6 98 2.1
6 0010000005韋伯19091220 1 0000337340 00000 LAB 1E + 19 20000128 085900

如何防止的 「docnr」 到變換「1E + 19」?

回答

1

...例如通過設置欄鍵入character,就像你一樣:

txt <- "0010000005|Weber|19091220|1|0000337340|00000|LAB|0000010000000000000011524|20000127|084800||140|3.7|100|2.1| 0010000005|Weber|19091220|1|0000337340|00000|LAB|0000010000000000000011541|20000127|080200|||||| 0010000005|Weber|19091220|1|0000337340|00000|LAB|0000010000000000000011562|20000127|101800||140|4.6|101|2.2| 0010000005|Weber|19091220|1|0000337340|00000|LAB|0000010000000000000011579|20000127|134500||138|4.0||2.2| 0010000005|Weber|19091220|1|0000337340|00000|LAB|0000010000000000000011591|20000128|084200||138|3.6|98|2.1| 0010000005|Weber|19091220|1|0000337340|00000|LAB|0000010000000000000011593|20000128|085900|||||| 0010000005|Weber|19091220|1|0000337340|00000|LAB|0000010000000000000011653|20000129|093400||140|4.2|99|2.2| 0010000005|Weber|19091220|1|0000337340|00000|LAB|0000010000000000000011717|20000129|094100||||||" 
txt <- gsub(" ", "\n", txt) 
colnames<-c("patnr","name","birthday","sex","casenr","Bew","Art","docnr","date","time","none","Na","K","Cl","Ca","corCa") 
classes <- rep("character",length(colnames)) 
ELYTE <- read.table(text = txt, skip=3,comment.char="", sep="|", col.names=colnames, header=FALSE, colClasses=classes) 
ELYTE 
# patnr name birthday sex  casenr Bew Art      docnr  date time none Na K Cl Ca corCa 
# 1 0010000005 Weber 19091220 1 0000337340 00000 LAB 0000010000000000000011579 20000127 134500  138 4.0 2.2  
# 2 0010000005 Weber 19091220 1 0000337340 00000 LAB 0000010000000000000011591 20000128 084200  138 3.6 98 2.1  
# 3 0010000005 Weber 19091220 1 0000337340 00000 LAB 0000010000000000000011593 20000128 085900       
# 4 0010000005 Weber 19091220 1 0000337340 00000 LAB 0000010000000000000011653 20000129 093400  140 4.2 99 2.2  
# 5 0010000005 Weber 19091220 1 0000337340 00000 LAB 0000010000000000000011717 20000129 094100       
相關問題