Get Started

read_csv

CSV files can be imported with read_csv(). It's a wrapper function around read_delim() that handles all the details for you. For example, it will assume that the first row contains the column names.

The dataset you'll be working with here is potatoes.csv (view). It gives information on the impact of storage period and cooking on potatoes' flavor. It uses commas to delimit fields in a record, and contains column names in the first row. The file is available in your workspace. Remember that you can inspect your workspace with dir().

This is a part of the course

“Introduction to Importing Data in R”

View Course

Exercise instructions

  • Load the readr package with library(). You do not need to install the package, it is already installed on DataCamp's servers.
  • Import "potatoes.csv" using read_csv(). Assign the resulting data frame to the variable potatoes.

Hands-on interactive exercise

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

# Load the readr package
library(____)

# Import potatoes.csv with read_csv(): potatoes
potatoes <- ____(____)
Edit and Run Code

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.

In addition to base R, there are dedicated packages to easily and efficiently import flat file data. We'll talk about two such packages: readr and data.table.

Exercise 1: readr: read_csv & read_tsvExercise 2: read_csv
Exercise 3: read_tsvExercise 4: readr: read_delimExercise 5: read_delimExercise 6: skip and n_maxExercise 7: col_typesExercise 8: col_types with collectorsExercise 9: data.table: freadExercise 10: freadExercise 11: fread: more advanced useExercise 12: Dedicated classes

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