Description Usage Arguments Examples
View source: R/ConvertDataTableColumns.R
Converts columns of a data.table object to specified classes. The transformation is made by reference, thus the changes are made directly to the object passed in and no copies are made.
1 | ConvertDataTableColumns(object, columnDefs, levelsFunc = NULL, ...)
|
object |
A data.table object whose column classes are to be converted |
columnDefs |
A list of column class definitions in a form "[ColumnName] = [ColumnClass]" |
levelsFunc |
Function used to initialize levels of factor columns. (def: NULL) |
... |
Additional arguments passed to |
1 2 3 4 5 6 7 8 | object <- data.table::data.table(RecordId = c("1", "2"), CD4 = c("233", "459"))
# Column definitions as named vector
columnDefs <- c(RecordId = "integer", CD4 = "numeric")
# Check class of columns before conversion
sapply(object, class)
ConvertDataTableColumns(object, columnDefs)
# Check class of columns after conversion
sapply(object, class)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.