dp_apply_schema {datapackage} | R Documentation |
Convert columns of data.frame to their correct types using table schema
Description
Convert columns of data.frame to their correct types using table schema
Usage
dp_apply_schema(
dta,
resource,
convert_categories = c("no", "to_factor", "to_code"),
reorder = TRUE,
...
)
Arguments
dta |
a |
resource |
an object with the Data Resource of the data set. |
convert_categories |
how to handle columns for which the field
descriptor has a |
reorder |
put the columns in the same order as the fields in the data resource. |
... |
additional arguments are passed on to the |
Details
Converts each column in dta
to the correct R-type using the type
information in the table schema. For example, if the original column type in
dta
is a character vector and the table schema specifies that the field is
of type number, the column is converted to numeric using the decimal
separator and thousands separator specified in the field descriptor (or default values
for these if not).
Value
Returns a copy of the input data.frame with columns modified to match the
types given in de table schema. When reorder = TRUE
columns are put in the
same order as in the data resource with fields not in the data resource put
at the back of the data.frame.
See Also
This function calls conversion functions for each of the columns, see
dp_to_number
, dp_to_boolean
, dp_to_integer
,
dp_to_date
. dp_to_datetime
, dp_to_yearmonth
,
and dp_to_string
.