- Open a new R Script and save it as a file called lesson1_activityD.R.
- Load the datasets library, and then the mtcars dataset with the following code:
library(datasets)data("mtcars")
- 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)
- Create a variable called hpcyl, which is equal to the horsepower per cylinders of each car as follows:
mtcars$hpcyl <- mtcars$hp/mtcars$cyl
- 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: