Reading from a path
What if your CSV file is saved in a different folder?
You'll need to define the path before using read.csv()
.
This is a part of the course
“Introduction to Importing Data in R”
Exercise instructions
- Define the path to
swimming_pools.csv
, which is located in the"datasets"
folder of the home directory.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Define the path
path <- ___("___", "___", "___")
path
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.
Chapter 1: Importing data from flat files with utils
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.delimExercise 6: Assigning column namesExercise 7: Column classesExercise 8: read.tableExercise 9: Final ThoughtsChapter 2: readr & 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 classesChapter 3: Importing Excel data
Excel is a widely used data analysis tool. If you prefer to do your analyses in R, though, you'll need an understanding of how to import .csv data into R. This chapter will show you how to use readxl to do so.
Exercise 1: readxl (1)Exercise 2: List the sheets of an Excel fileExercise 3: Import an Excel sheetExercise 4: Reading a workbookExercise 5: readxl (2)Exercise 6: The col_names argumentExercise 7: The skip argumentChapter 4: Reproducible Excel work with XLConnect
Beyond importing data from Excel, you can take things one step further with XLConnect. Learn all about it and bridge the gap between R and Excel.
Exercise 1: Reading sheetsExercise 2: Connect to a workbookExercise 3: List and read Excel sheetsExercise 4: Customize readWorksheetExercise 5: Adapting sheetsExercise 6: Add worksheetExercise 7: Populate worksheetExercise 8: Renaming sheetsExercise 9: Removing sheetsWhat is DataCamp?
Learn the data skills you need online at your own pace—from non-coding essentials to data science and machine learning.