2017-11-25 70 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 

(结尾处的多余的数字出现,因为这个号码无法精确的双精度浮点表示)