Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Reading from a file
8. Setting column names
Reading from an Excel file


Let's look at another report. It's about our South American mines, and these managers always send reports without column names as a .txt file with a / separator. Well, with read.table(), this is not a problem. We'll just set the parameters as follows:

Fortunately, the read.table() function has the col.names option, which allows you to add names for column names while reading the file.

elemental_extracts_mines <- read.table(
  sep = "/",
  col.names = c("id", "first_name", "last_name", "productivity"))

We must provide the new column names as a vector if we want to add columns named id, first_name, last_name, and productivity.


Load the data from data/elemental_extracts_mines.txt into the elemental_extracts_mines variable. Use the read.table() function and set the separator as "/". Use the col.names option to create the following column names: id, first_name, last_name, and productivity. Use the head() function to preview the data.