R 科学记数法错误地转换成数字
我有一个带有科学符号数字的数据表,如R 科学记数法错误地转换成数字,r,scientific-notation,R,Scientific Notation,我有一个带有科学符号数字的数据表,如1.1e-07 当我尝试使用as.numeric将这些数字转换为正常数字时,R给出了错误的数字,如: 1.1e-07: 5977 1.4e-06: 5633 等等 我怎样才能解决这个问题 更新:谢谢,这真的是关于因素的。你的数字很可能被定义为因素。这将导致as.numeric不返回输入的“值”,而是返回因子级序列号 x <- as.factor(c(1.1e-7, 2e-8)) ## convert two numbers to fac
1.1e-07
当我尝试使用as.numeric将这些数字转换为正常数字时,R给出了错误的数字,如:
1.1e-07: 5977
1.4e-06: 5633
等等
我怎样才能解决这个问题
更新:谢谢,这真的是关于因素的。你的数字很可能被定义为因素。这将导致
as.numeric
不返回输入的“值”,而是返回因子级序列号
x <- as.factor(c(1.1e-7, 2e-8)) ## convert two numbers to factors
as.numeric(x)
[1] 2 1
顺便说一下,科学记数法是R格式的标准。
将数字转换为字符。输入数据的类型是什么?如果这是一个因素,那么我会期待你的错误结果。你从哪里得到这些数据?几乎可以肯定它们是作为因子输入的。
as.numeric(as.character(x))
[1] 1.1e-07 2.0e-08
format(as.numeric(as.character(x)), scientific = F)
[1] "0.00000011" "0.00000002"