2017-11-25 71 views
2

代碼示出了如:解析雙分組數目與readr :: parse_double()

readr::parse_double("123,456,789.987", 
        locale = locale(decimal_mark = ".", 
            grouping_mark = ",")) 

其中預期的結果是:123456789.987
但原來的錯誤:

1 parsing failure. 
row # A tibble: 1 x 4 col  row col    expected  actual 
expected <int> <int>     <chr>  <chr> actual 1  1  
NA no trailing characters ,456,789.987 
[1] NA 
attr(,"problems") 

我想知道爲什麼發生這種情況以及如何解決它?

回答

0

我不知道,但它看起來像你需要parse_number:從?parse_number

The grouping mark specified by the locale is ignored inside the number.

parse_double()幫助頁面不說忽略分組標記,但它不「T說,它...

print(parse_number("123,456,789.987"),digits=20) 
## [1] 123456789.98700000346 

(結尾處的多餘的數字出現,因爲這個號碼無法精確的雙精度浮點表示)