1. Learn
  2. /
  3. Courses
  4. /
  5. Introduction to Importing Data in R

Connected

Exercise

Column classes

The colClasses argument allows you to specify the data types for each column of the file you are reading. This can improve the efficiency of the import process and ensure that the columns are read in with the correct data types.

You can do this by setting the colClasses argument:

read.delim("my_file.txt", 
           colClasses = c("character",
                          "numeric",
                          "logical"))

If a column is set to "NULL" in the colClasses vector, this column will be skipped and will not be loaded into the data frame.

Instructions

100 XP
  • The hotdogs data frame has been loaded. Go ahead and display the structure of hotdogs.
  • In the colClasses argument of the second read.delim() call, set the first, second, and third columns to 'character', 'NULL' and 'numeric'.
  • Display the structure of hotdogs2 and look for the difference.