Lab 00: Install R and R Studio

Author

Seoncheol Park

Introduction

Welcome to the world of statistical programming!

  • How to download and install R

  • How to download and install RStudio, an integrated development environment (IDE)

  • Alternatively, you can use VScode with R and Rstudio extension. In this class, however, we will mainly focus on R studio.

Install R and RStudio

Getting started in RStudio

  • When you are working in RStudio, you’ll see a display something like

A typical RStudio display.
  • The display includes four panes.
    • The top left pane is the Source Pane, or editor. You will type your program (or other document) there. You can have several open files in this pane; the tabs allow you to choose which is active.
    • The bottom left pane is called the Console Pane. This is where you communicate with R. You can type directly into this pane, but it is usually better to work within the editor pane, because that way you can easily correct mistakes and try again.
    • The two right-hand panes contain a variety of tabs. In the figure, the top pane is showing the Environment Pane (i.e. the workspace), and the bottom pane is showing a plot.
  • For now, you just need to know the following points:
    • You should do most of your work in the editor, but you can occasionally type in the console.
    • The console pane displays what R is doing.
    • All of the panes can be resized and repositioned, so sometimes it may appear that you’ve lost one, but there’s no need to worry: just find the header of the pane and click there with your mouse, and the pane will reappear. If the pane is there but the content isn’t what you want, try clicking on the tabs at the top.

Exercises

Basic R exercise

Here’s a simple exercise with an empty code chunk provided for entering the answer.

1. Write the R code required to add two plus two:

Exercise with R function

2. Now write an R function add that adds any two numbers and then call it:

Assignment

You can use <- or = to assign values to a specific variable:

3. Now write an R variable studentinfo which contains your student ID and name:

Number of rows

4. Modify the following code to limit the number of rows printed to 5:

Submit your answers on the course website!