4.6 Load data included with R - Video Tutorials & Practice Problems
Video duration:
1m
Play a video:
Video transcript
<v Voiceover>Many R packages</v> come with data included right in them. Getting to this data is a fairly simple process and it allows you to experiment with all these great data sets. A particularly favorite data set of mine is in ggplot2. So in order to get at the data, we first have to load ggplot2. So require ggplot2. Running that loads the package. To grab the data you simply type data, diamonds. Run that and you now have access to the diamonds data set, which looks roughly like this. That's all there is to it. Now there's another package called reshape2 that has a data set on tips. So let's say I wanna grab that data without actually loading the package. I can do this using the data called, once again, with a few more arguments. What I do is data, the name of the data in quotes, in this case tips and then package equals reshape2 in quotes. Doing that gives me access to the tips data. There you have it. To see a list of data that's available to you as an R user, just type in data, open and closed parentheses. This brings up a new pane in our studio that shows you the various different data sets available. There's airline passengers, there's sales data, there's carbon dioxide uptake. All sorts of information. It even breaks down what data is available and what packages. So grabbing data from within R package or R itself is an easy process using the data function.