Restore the type of columns according to a reference data frame
Source:R/data_restoretype.R
data_restoretype.Rd
Restore the type of columns according to a reference data frame
Arguments
- data
A data frame for which to restore the column types.
- reference
A reference data frame from which to find the correct column types. If
NULL
, each column is converted to numeric if it doesn't generateNA
s. For example,c("1", "2")
can be converted to numeric but notc("Sepal.Length")
.- ...
Currently not used.
Examples
data <- data.frame(
Sepal.Length = c("1", "3", "2"),
Species = c("setosa", "versicolor", "setosa"),
New = c("1", "3", "4")
)
fixed <- data_restoretype(data, reference = iris)
summary(fixed)
#> Sepal.Length Species New
#> Min. :1.0 setosa :2 Length:3
#> 1st Qu.:1.5 versicolor:1 Class :character
#> Median :2.0 virginica :0 Mode :character
#> Mean :2.0
#> 3rd Qu.:2.5
#> Max. :3.0