ConvertDataTableColumns {hivEstimatesAccuracy} | R Documentation

## ConvertDataTableColumns

### Description

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.

### Usage

    ConvertDataTableColumns(object, columnDefs, levelsFunc = NULL, ...)

### Arguments

`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 `levelsFunc`.

### Examples

    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)

[Package hivEstimatesAccuracy version 1.10.0 Index]