[英]Is there an R function to convert non-standard scientific notation?
I'm presently working with a dataset (made from a biostatistics research project) which denotes expression ranks in a value such as "1.00e3" rather than "1.00e+03" which seems to confuse the system when ranking.我目前正在使用一个数据集(由生物统计研究项目制成),该数据集以“1.00e3”而不是“1.00e+03”等值表示表达排名,这在排名时似乎会混淆系统。 Does anyone have any ideas as to how to work within the data frame to force it to convert "e" notations to standard form?
有没有人对如何在数据框中工作以强制将“e”符号转换为标准形式有任何想法? I have already tried scipen and formatC.
我已经尝试过 scipen 和 formatC。
It seems you are trying to rank a character vector numerically.您似乎正在尝试按数字对字符向量进行排名。 Which can indeed go awry.
这确实会出错。 The trick is to convert to numeric for ranking.
诀窍是转换为数字进行排名。
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
If you really need the values in character format rather than numeric (which seems unlikely), you can do如果您确实需要字符格式而不是数字格式的值(这似乎不太可能),您可以这样做
format(as.numeric(x), scipen=999)
# [1] "1e+03" "1e+04" "1e+05"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.