> X864291X8X74
[1] 8.0000000000 9.0000000000 10.0000000000 6.0000000000 8.0000000000
10 Levels: 0.0000000000 10.0000000000 12.0000000000 3.0000000000 4.0000000000 6.0000000000 ... NULL
> as.numeric(X864291X8X74)
[1] 8 9 2 6 8
what did I misunterstood? shouldn't be the result of as.numeric 8 9 10 6 8?
How do I get the correct result?
as. numeric attempts to coerce its argument to numeric type (either integer or real). is. numeric returns TRUE if its argument is of type real or type integer and FALSE otherwise.
It is a historical anomaly that R has two names for its floating-point vectors, double and numeric (and formerly had real ). double is the name of the type. numeric is the name of the mode and also of the implicit class. As an S4 formal class, use "numeric" .
To convert an integer to double in R, use the as. double() method. The as. double() is an inbuilt R function that converts an integer to the double class.
There are two steps for converting factor to numeric: Step 1: Convert the data vector into a factor. The factor() command is used to create and modify factors in R. Step 2: The factor is converted into a numeric vector using as. numeric().
Your vector is a factor
. This question has been asked quite a few times, ex: here, here, here. In order to convert a factor to numeric, you'll have to convert to character
first. Try:
as.numeric(as.character(my_vec))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With