A1 – Introduction

Before starting this lab, I recommend you open up a copy of the recommended book Art of R Programming by Matloff. See the syllabus for information on how to obtain this book.

Installation and Setup

First, make sure you have R and R Studio installed on your laptop. Go to http://www.r-project.org/ to download and install R, and http://rstudio.org/ to download and install R Studio. (You will need both for the intensive courses following this one as well.)

We will only use R in interactive mode for this portion of the lab, which requires you to open up an R console. There are three ways to get to an R console if you have everything properly installed:

  • Open a terminal or command-prompt. Type "R" and press Enter.
  • Find where you installed R and double-click on the R icon to open the default GUI program.
  • Use the Console pane in R Studio.

Either way, you should see the following output:

R version 2.15.1 (2012-06-22) -- "Roasted Marshmallows"
Copyright (C) 2012 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

>

Your version number may be newer (but should not be older). The > sign at the bottom is called the prompt. This is where you enter R commands, and differentiates your commands from the output.

Lab Exercise

For this portion of the lab, please answer the following questions. If you get stuck, ask the instructor for help. When finished, show your console history to the instructor for credit.

Operations and Modes

For each of these questions, use the following math operators:

  • + addition
  • subtraction
  • * multiplication
  • / division
  • ^ power
  • %% modulo

Question: Use R to calculate the following values:

4 + 3
4 – 3
4 * 3
4 ^ 3
4 / 3
4 %% 3
4 %/% 3

Question: What is the difference between 4 / 3 and 4 %% 3 and 4 %/% 3 (i.e. what operations does / versus %% versus %/% perform)?

Question: What does 4 / 0 return?  What does mode(4 / 0) return?

Question: What does 0 / 0 return?  What does mode(0 / 0) return?

Question: What is the mode for Inf, NaN, and NULL values?

Question: Use R to calculate the following values:

1 + TRUE
1 + FALSE
TRUE / FALSE

Question: What value does R map to TRUE? What value does R map to FALSE?

Question: Use R to calculate the following values:

mode(100)
mode("100")
mode("hello")
mode(TRUE)
mode(1 & 0)
mode(mode)

Getting Help

Question: Run the following command and observe the output:

getwd()

Question: Run the following command and observe the output:

getwd

Question: What is the difference between getwd() and getwd when run in the console?

Question: Run the following command and read the description from the help output:

help(getwd)

Question: Run the following command and observe the output:

help(>)

Question: How do you get help on the greater-than > symbol?

Comments