Get Started

read.delim

Aside from .csv files, there are also the .txt files which are basically text files. You can import these files with read.delim(). By default, it sets the sep argument to "\t" (fields in a record are delimited by tabs) and the header argument to TRUE (the first row contains the field names).

In this exercise, you will import hotdogs.txt (view), containing information on sodium and calorie levels in different hotdogs (Source: UCLA). The dataset has 3 variables, but the variable names are not available in the first line of the file. The file uses tabs as field separators.

This is a part of the course

“Introduction to Importing Data in R”

View Course

Exercise instructions

  • Import "hotdogs.txt" with read.delim(). Call the resulting data frame hotdogs. The variable names are not on the first line, so make sure to set the header argument appropriately.
  • Call summary() on hotdogs. This will print out some summary statistics about all variables in the data frame.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Import "hotdogs.txt": hotdogs
hotdogs <- ___

# Summarize hotdogs
___

This exercise is part of the course

Introduction to Importing Data in R

BeginnerSkill Level
4.2+
26 reviews

In this course, you will learn to read CSV, XLS, and text files in R using tools like readxl and data.table.

A lot of data comes in the form of flat files: simple tabular text files. Learn how to import the common formats of flat file data with base R functions.

Exercise 1: Introduction & read.csvExercise 2: read.csvExercise 3: Reading from a pathExercise 4: read.delim & read.tableExercise 5: read.delim
Exercise 6: Assigning column namesExercise 7: Column classesExercise 8: read.tableExercise 9: Final Thoughts

What is DataCamp?

Learn the data skills you need online at your own pace—from non-coding essentials to data science and machine learning.

Start Learning for Free