read_tsv
Where you use read_csv()
to easily read in CSV files, you use read_tsv()
to easily read in TSV files. TSV is short for tab-separated values.
This time, the potatoes data comes in the form of a tab-separated values file; potatoes.txt
(view) is available in your workspace. In contrast to potatoes.csv
, this file does not contain columns names in the first row, though.
There's a vector properties
that you can use to specify these column names manually.
This is a part of the course
“Introduction to Importing Data in R”
Exercise instructions
- Use
read_tsv()
to import the potatoes data frompotatoes.txt
and store it in the data framepotatoes
. In addition to the path to the file, you'll also have to specify thecol_names
argument; you can use theproperties
vector for this. - Call
head()
onpotatoes
to show the first observations of your dataset.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Column names
properties <- c("area", "temp", "size", "storage", "method",
"texture", "flavor", "moistness")
# Import potatoes.txt: potatoes
potatoes <- ___
# Call head() on potatoes
___
This exercise is part of the course
Introduction to Importing Data in R
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_csvExercise 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 classesWhat is DataCamp?
Learn the data skills you need online at your own pace—from non-coding essentials to data science and machine learning.