r_data_types infers correct data classes for each column in a data.frame
Source:R/r_data_types.R
r_data_types.Rd
Read an input data set and infer the correct columnar r data types. Includes numeric, logical or factor type of the data columns
Examples
## ------------------------------------------------------------
## -------- pbc data
# We need to create this dataset
data(pbc, package = "randomForestSRC" )
# Show data types for each column
sapply(pbc,class)
#> days status treatment age sex ascites
#> "integer" "integer" "integer" "integer" "integer" "integer"
#> hepatom spiders edema bili chol albumin
#> "integer" "integer" "numeric" "numeric" "integer" "numeric"
#> copper alk sgot trig platelet prothrombin
#> "integer" "numeric" "numeric" "integer" "integer" "numeric"
#> stage
#> "integer"
# Correct types
pbc <- r_data_types(pbc)
sapply(pbc,class)
#> days status treatment age sex ascites
#> "integer" "logical" "logical" "integer" "logical" "logical"
#> hepatom spiders edema bili chol albumin
#> "logical" "logical" "factor" "numeric" "integer" "numeric"
#> copper alk sgot trig platelet prothrombin
#> "integer" "numeric" "numeric" "integer" "integer" "numeric"
#> stage
#> "factor"