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

  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 with the following code:
library(datasets)data("mtcars")
  1. View mtcars with the str() function to see the data names, types, and how many observations and variables there are. The code will be as follows:
str(mtcars)
  1. Create a variable called hpcyl, which is equal to the horsepower per cylinders of each car as follows:
mtcars$hpcyl <- mtcars$hp/mtcars$cyl
  1. Write mtcars into a .csv file called mtcars_out.csv. If you have a program installed that will allow it, open it on your computer and verify that the hpcyl variable is inside. The code will be as follows:
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