Introduction to R
Data's about to get graphic.
- Course Length: 3 weeks
- Course Type: Short Course
- Category:
- High School
- Technology and Computer Science
Schools and Districts: We offer customized programs that won't break the bank. Get a quote.
Whether you like it or not, any time you log in to your favorite social network, someone's sitting behind your monitor taking detailed notes on your love for Doritos Locos Tacos and your interest in the promise of a Pusheen movie. After all, that's the glory—and perhaps the inherent creepiness—of living in the Information Age.
In this three-week course, we aren't going to read all the fine print on what you're giving Facebook for its latest social engineering project. Through the powers of R-programming, though, we can learn how social networks manage all that data and use it to answer the biggest questions of the Modern Internet. R can also handle other big data questions besides the ones that make you feel like you're always being watched.
Like…which Doritos flavors make the best tacos.
R's all about data—specifically, cleaning up and analyzing data sets. In Shmoop's Intro to R, you're going to learn everything you need to know about R to turn giant piles of messy data into something people can actually read and understand. Between the
- data structures like vectors, matrices, and data frames
- conditionals and loops that help control when things happen
- functions—either from R or you—that can make tasks repeatable
you'll be using R to solve the big data questions in no time. Even if those questions only tell you that looking at pictures of comically fat cats makes you crave Cool Ranch-flavored Tex Mex .
Unit Breakdown
1 Introduction to R - Introduction to R
Between conditions, loops, functions, and graphics, you'll be up and ready to go analyzing your own data in no time. Your own data sold separately.
Sample Lesson - Introduction
Lesson 1.02: RStudio, the Interface, the Language, the Legend
(Source)
Welcome to our studio: RStudio. Every programming language has an environment, and this is R's. Programming environments are all about making your life easier. Whether it's warning you about a potential error or just plain stopping you from crashing your computer, RStudio's here to help.
RStudio is the most popular environment to start writing R code in for a couple of reasons:
- It's generally agreed to be the best R IDE out there.
- It's a pun. Go ahead, read it out loud. We'll wait.
- …there aren't a lot of other options.
Did we mention that R is meant pretty much entirely for statistical analysis? Turns out when you pigeon-hole your software that much, there aren't that many people working on it, meaning that there aren't many people trying to make different environments when the native environment works well.
There are some other options, though, but R's considered the best. It gives you the tools you need to analyze data all in one screen, including writing code, debugging code, and analyzing graphs. Plus, the user interface rocks.
Even if there aren't a lot of other user interfaces to choose from.
Sample Lesson - Reading
Reading 1.1.02: RStudio, in the Middle of RStreet
We're going to introduce you to RStudio in just a minute. Just to be fair, though, we should probably let you look at the other code editors you can use.
If you're into that kind of thing.
Every code editor's a little different. They all want to make your life as a programmer easier, but how they do that is in different ways. Sometimes they're a console like what you'd see in your favorite retro cyberpunk thriller. Other times you'll see something with buttons and menus (which is usually known as a graphical user interface, FYI).
Then there are the complex code editors: the Integrated Development Environments (also known as IDEs). These are huge applications that know your language really well. So well they can autocomplete your lines and tell you when a syntax error could happen before you even show the code to your CPU. RStudio is an IDE, and it's going to help you a ton as you start to learn this whole coding thing.
If you're more of a go-your-own-route kind of person, though, you could also use
Since we're going to be using RStudio for all our examples, though, if you're just starting out, then go with the one we're using. Trust us; it'll make your life that much easier.
Installing RStudio
How to install RStudio?
Just like, uh…any software, to be able to use RStudio you have to download and install it. If you don't have experience…downloading things, we'll walk you through it one step at a time.
First thing you need to do: download the software. Before you download RStudio, you'll need to download R here.
Once R's nice and settled on your computer, you can move on to downloading RStudio. The trick is finding the right file to download. In the "Installers for Supported Platforms," pick the file that matches your operating system, whether it's
- Windows.
- Mac.
- Ubuntu.
- Fedora/RedHat.
If you know what you're doing and you're on a UNIX system, you can totally pick the Zip/Tarballs option, but it's probably more trouble than it's worth if you've got an option for an installer. The installer's going to make sure everything connects up to your operating system the way it should.
Once you've downloaded your file, you'll want to run it.
Go figure.
Once you've clicked on it to make things work, follow the installation steps. We say just go with the default installation. It makes things easier. You might also get the option to put an icon on the desktop. That decision—along with where the application should live—is up to you.
Once all those options are done, you should be up and ready to roll.
The frame on the right is your workspace. If you click on the "History" tab, you'll find the list of commands you already entered.
The lower right frame has a number of tabs, too, but the most important one is "Plots." Plots will show you any graphs you make in R.
Don't worry: we'll go over it later.
When you open RStudio, the left half of your screen should be the Console. You'll be able to write code here, but if you want to save any of your work, you'll want to click on the icon of a page with a plus sign on top.
You'll open a menu with options. Too many options. Just pick "R Script." That's going to give you a file you can save your actions to. That frame in general is called the Editor. You'll be using it.
All. The. Time.
Underneath the Editor is the Console. Every time you open RStudio, you'll see the R version the computer's running and some general information about R. Below that information is the prompt. The prompt lets you try out little pieces of code quickly. If you aren't sure something will run the way you want it to, that's your place to test things out.
It's also the place where you'll see all the results from running a program.
Wait, what?
We'll cover that more later. All you need to know is that when you write and run lines of code in the editor, it'll show up in the console.
For now, all you need to do is learn how to say hello.
(Oops, did we give away the first activity?)
Sample Lesson - Activity
Activity 1.02: The One with the First Line of Code
Enough talk about RStudio. It's time to get started with your first lines of R. We'll get you speaking in R better than Joey Tribbiani speaks French.
(Admittedly, that isn't saying much, but still.)
It'll be just like speaking in English, except…to the console…and nobody talks back.
Step One
Open RStudio. If you haven't downloaded either R or RStudio yet, do it now. Here, we'll give you the links again:
Everyone on the same application? Good.
Turn that upper right window so that it shows you the History tab. That way you'll keep track of everything.
Step Two
Look at the console screen. See that blue greater-than sign? That's where you'll be writing lines of code today. Later on, you'll make and save scripts, but for now you can just worry about one line at a time.
The line you'll print? A time-honored tradition amongst coders: "Hello, World." It all started with a little language called C (maybe you've heard of it?), and now it's so beloved as an arbitrary starting sentence that everyone uses it.
No, seriously. It was chosen arbitrarily, and computer scientists love it more than they love calling variables "foo" and "bar," which are also both arbitrary names you'll hear about all the time.
Are you noticing a pattern here? Because we are.
In the console, you'll be using the print()
command, which looks just like this:
→ print("Anything you want to print")
Any time you use keyboard letters, you'll need to surround them in quotes. That's just the rule. Just call your print()
function with the words "Hello, World!" inside it. Then take a screenshot by pressing
- CMD + Shift + 4 on Mac
- the Snipping Tool on Windows
and making a square around the console with your cursor. Then upload it below and say, "Goodbye, Activity."
Creative Visual Presentation Rubric - 50 Points
- Course Length: 3 weeks
- Course Type: Short Course
- Category:
- High School
- Technology and Computer Science
Schools and Districts: We offer customized programs that won't break the bank. Get a quote.