[英]Is there an R function to convert non-standard scientific notation?
我目前正在使用一个数据集(由生物统计研究项目制成),该数据集以“1.00e3”而不是“1.00e+03”等值表示表达排名,这在排名时似乎会混淆系统。 有没有人对如何在数据框中工作以强制将“e”符号转换为标准形式有任何想法? 我已经尝试过 scipen 和 formatC。
您似乎正在尝试按数字对字符向量进行排名。 这确实会出错。 诀窍是转换为数字进行排名。
x = c("1.00e3", "1.00e+04", "1.0e05")
sort(x)
# "1.00e+04" "1.00e3" "1.0e05"
sort(as.numeric(x))
# 1e+03 1e+04 1e+05
如果您确实需要字符格式而不是数字格式的值(这似乎不太可能),您可以这样做
format(as.numeric(x), scipen=999)
# [1] "1e+03" "1e+04" "1e+05"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.