Lesson 1: Introduction to RWhat you'll learnLessonWhat does this mean? Why is this happeningInstalling RInstall RStudioPackages
Before class (on your own)
In class
Understand basic elements of RStudio and how to use them
Set up a workflow using RMarkdown
Now we're beginning our R unit. As with Excel, there is wide variation in our baseline background with R, perhaps even more so! We will take two weeks to set aside all policy applications and just think about R.
Never used R: This is where I am teaching from. If I get too jazzed and you need extra clarification/help, please each out to group mates who have used R and will be able to explain things in a new/different way. If they are stumped, reach out to me!
Used R but rusty: This should be just right for you, but there will be some review. Enjoy the easy ride!
Confident R user: There will be a lot of review. I will occasionally provide alternative activities you can do instead of the assigned ones if you want to push yourself. It is up to you which you do (and you can jump back and forth, depending on your workload).
Things might get a bit tricky now! Don't worry. It will pay off.
ggplot
and friends.What if I'm lost?
For those of you with some R experience, you may be familiar and comfortable uniting the power of R with RMarkdown and Git. I'm happy for you to do either or both. In terms of the support I an provide, I'm quite experienced with RMarkdown and "decently competent beginner" at Git.
You can download R from CRAN. Select your operating system.
Windows users: Select base
, and then download and install R
Mac users: Download and install R-4.04.pkg
If you get an error message, then you should hold down the control
key while clicking the package, then select "open" (still holding the key), and once you see a warning message, select "open."
Then, you need to download RStudio. You can either get the standard version (RStudio Desktop) here, or you can grab a "preview" version, which has fun new updates. I recommend preview version, but it's your call.
Once you have both installed, open RStudio. You know things are good if you see something that looks like a emptier, sadder version of this.
Now, the test to see if things are working.
a. Put your cursor in the pane labelled Console
b. Type the following: x <- 2*2
and press enter/return. You've made an object! it's name is x
and it's equal to 2*2
c. Type the following: x
and press enter/return. This prints the object. Do you see the number 4? Success!
What if you are stuck? Head to Teams!
R itself can do all sorts of neat statistical things. But, the bulk of its functionality is not included in the base installation. Rather, we need packages.
Packages are a set of programs that live on your computer. You only need to install them once. We will need three important packages:
We can easily install them using the install.packages
command. Type the following into your command window and press enter
xxxxxxxxxx
install.packages("dplyr", dependencies = TRUE)
Notice that there are two parts:
"dplyr"
- the name of the package in double-quotation marks; and dependencies = TRUE
- which tells R to make sure to download any packages that dplyr
needs to run properly. This is optional.