作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
可能有人问过这个问题,但我没有设法找到一个简单的解决方案。有没有办法将数字转换为其科学记数法,但以 10^ 的形式而不是默认的 e+ 或 E+ 的形式?所以 1000 会变成 1*10^3 而不是 1e+3。谢谢!
最佳答案
要打印数字,您可以将其视为字符串并使用 sub
重新格式化它:
changeSciNot <- function(n) {
output <- format(n, scientific = TRUE) #Transforms the number into scientific notation even if small
output <- sub("e", "*10^", output) #Replace e with 10^
output <- sub("\\+0?", "", output) #Remove + symbol and leading zeros on expoent, if > 1
output <- sub("-0?", "-", output) #Leaves - symbol but removes leading zeros on expoent, if < 1
output
}
> changeSciNot(5)
[1] "5*10^0"
> changeSciNot(-5)
[1] "-5*10^0"
> changeSciNot(1e10)
[1] "1*10^10"
> changeSciNot(1e-10)
[1] "1*10^-10"
关于r - 在 R 中,使用科学记数法 10^ 而不是 e+,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29785555/
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引起辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the he
我是一名优秀的程序员,十分优秀!