Convert data to numeric by converting characters to factors and factors to either numeric levels or dummy variables.

convert_data_to_numeric(x, dummy_factors = TRUE, ...)

data_to_numeric(x, dummy_factors = TRUE, ...)

Arguments

x

A data frame or a vector.

dummy_factors

Transform factors to dummy factors (all factor levels as different columns filled with a binary 0-1 value).

...

Arguments passed to or from other methods.

Value

A data frame of numeric variables.

Examples

head(convert_data_to_numeric(iris))
#>   Sepal.Length Sepal.Width Petal.Length Petal.Width Species.setosa
#> 1          5.1         3.5          1.4         0.2              1
#> 2          4.9         3.0          1.4         0.2              1
#> 3          4.7         3.2          1.3         0.2              1
#> 4          4.6         3.1          1.5         0.2              1
#> 5          5.0         3.6          1.4         0.2              1
#> 6          5.4         3.9          1.7         0.4              1
#>   Species.versicolor Species.virginica
#> 1                  0                 0
#> 2                  0                 0
#> 3                  0                 0
#> 4                  0                 0
#> 5                  0                 0
#> 6                  0                 0