问题
I've got a table of data with scientific notation numbers such as 1.1e-07
.
When I try to convert these numbers to normal numbers with as.numeric, R gives me wrong numbers, like:
1.1e-07: 5977
1.4e-06: 5633
etc.
How can I fix this?
Update: thanks, it really was about factors.
回答1:
Your numbers are most probably defined as factors. This will result in as.numeric
not returning the "value" of the input but the factor level sequence number.
x <- as.factor(c(1.1e-7, 2e-8)) ## convert two numbers to factors
as.numeric(x)
[1] 2 1
To solve this problem make sure you read in the data not as factors from you data source.
Note that a quick and dirty solution would be something like
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"
By the way, scientific notation is standard in R. format
casts the numbers as character.
来源:https://stackoverflow.com/questions/40655701/scientific-notation-wrongly-converts-to-numbers