Reading scientific notation D+

筅森魡賤 提交于 2019-12-11 22:05:35

问题


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))


来源:https://stackoverflow.com/questions/29166012/reading-scientific-notation-d

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!