Specifying column classes
The colClasses
argument of fread()
allows you to explicitly specify the class of the columns. You can specify the class of the columns as a character vector (as is done in base R functions such as read.csv()
):
colClasses = c("integer", rep("factor", 3), "character")
However, this format requires you to specify the classes of all columns. This can be problematic if the file contains several columns and you only want to explicitly specify classes for some columns and leave the rest as default. You can use a more convenient list format for this purpose:
colClasses = list(factor = 2:4)
Here, the columns two through four are imported as factors and the rest are imported using fread()
's defaults.
Este exercício faz parte do curso
Data Manipulation with data.table in R
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
# Import using read.csv with defaults
base_r_defaults <- ___("sample.csv")
___(base_r_defaults)