Skip to Content
R Programming Fundamentals
book

R Programming Fundamentals

by Kaelen Medeiros
September 2018
Beginner
206 pages
4h 27m
English
Packt Publishing
Content preview from R Programming Fundamentals

Activity: Exporting and Importing the mtcars Dataset

Scenario

You have been asked to calculate a new variable in the mtcars built-in dataset and export the data so that you can email it to a colleague.

Aim

To export a dataset to a .csv file, edit it, and import it back into R using the appropriate functions.

Prerequisites

You must have R and RStudio installed on machine. Notepad, MS Excel, or any other program that can open .txt and .csv files will also be helpful.

Steps for Completion

  1. Open a new R Script and save it as a file called lesson1_activityD.R.
  2. Load the datasets library, and then the mtcars dataset.
  3. Create a variable called hpcyl equal to the horsepower per cylinders of each car.
  4. Write mtcars into a .csv file called mtcars_out.csv ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

R Programming Fundamentals

R Programming Fundamentals

Samik Sen, Marcin Dubel
Python for Programmers

Python for Programmers

Paul Deitel, Harvey Deitel

Publisher Resources

ISBN: 9781789612998Supplemental Content