2014-01-27 51 views
2

與小數進口我想要導入這些數據雙不是R中

Id_points; x; y; z; remarks 
1; 2562156.119; 1122172.393; 425.627; capteur 
2; 2562155.844; 1122172.412; 420.709; 

我用下面的代碼

S1<-read.csv2('section_raw_data.csv', header=TRUE, sep = ";", dec = ".", fill=TRUE, colClasses=c('integer', 'double', 'double','double','character')) 

生成的數據幀是:

Id_points; x; y; z; remarks 
1; 2562156; 1122172; 425.627; capteur 
2; 2562155; 1122172; 420.709;  

沒有人有一個想法爲什麼前兩個雙數被截斷爲小數?

+0

@tonytonov'double'是'R中numeric'的代名詞:看'double'? – Roland

+0

@Roland謝謝,刪除評論。 – tonytonov

+0

有沒有什麼方法可以針對R-FAQ標籤這樣的多重問題? –

回答

2

它們僅用於打印。內部表示是雙重的。

S1<-read.csv2(text="Id_points; x; y; z; remarks 
1; 2562156.119; 1122172.393; 425.627; capteur 
2; 2562155.844; 1122172.412; 420.709; ", 
       header=TRUE, sep = ";", dec = ".", fill=TRUE, 
       colClasses=c('integer', 'double', 'double','double','character')) 

sprintf("%f",S1$x) 
#[1] "2562156.119000" "2562155.844000" 
+0

打印到控制檯的數字位數可以用'options(digits = your_choice_here)'來調整' –