Home > Software engineering >  How do I convert data from integer and dbl to numeric in R
How do I convert data from integer and dbl to numeric in R

Time:10-20

As stated above, I'm trying to convert data in my dataframe from integer/dbl to numeric but I end up with dbl for both columns.

Original dataset

Code I'm using to convert to numeric;

data$price <- as.numeric(data$price)
data$lot_size <- as.numeric(data$lot_size)

The dataframe I end up with: The dataframe I end up with

Dataset I have been working with: https://dasl.datadescription.com/datafile/housing-prices-ge19

CodePudding user response:

"numeric is identical to double" https://stat.ethz.ch/R-manual/R-devel/library/base/html/numeric.html

> typeof(as.numeric(3L))
[1] "double"
> typeof(as.integer(3L))
[1] "integer"

CodePudding user response:

The stuff with types in R is a bit confusing. I would say that ´numeric´ is not really a data type at all in R. You will never get the answer numeric from the typeof function.

Both, integers and doubles are considered to be numeric and the function is.numeric will return TRUE for either.

On the other hand, numeric is more often a synonym for double. The functions numeric and as.numeric are the same as double and as.double.

  • Related