Reading scientific notation D+

2019-09-08 02:55发布

问题:

How can I read data in scientific notation (D+) format into R?

e.g.

-0.416932D+01, -0.412300D+02

回答1:

Solution using stringr package:

library(stringr)  
x <- c("-0.416932D+03")
as.numeric(str_replace(x, "D", "e"))
[1] -416.932

If you prefer not to use external packages, you can use the gsub function from the base package:

as.numeric(gsub("D","e",x))