Introduction

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

favstats(fastest~seat,data=m111survey)
##       seat min    Q1 median  Q3 max     mean       sd  n missing
## 1  1_front  60 90.00    100 119 130 102.2593 19.15241 27       0
## 2 2_middle  80 90.00    100 110 143 102.9688 15.34230 32       0
## 3   3_back  90 97.25    115 130 190 121.9167 30.09820 12       0

You can also embed plots, for example:

bwplot(fastest~seat,data=m111survey,
       xlab="Seating Preference",
       yalb="Fastest Speed Driven (mph)",
       main="Speed and Seating at GC")

Practice

use R to add 2 and 2, by inserting the appropriate command inside the code chunk below.

2+2
## [1] 4

Dolphin Communication: Your Coin Flips

How many heads did you get?

8 ## Dolphins Again: Your App Simulations

How many times did you simulate?

1800001

What percentage of the time did you get 15 or more heads?

.03

Suppose Buzz is just guessing: about what’s the chance that he would get 15 or more correct?

.03

Based on your results, do you think we have strong evidence that Buzz and Doris can communicate?

yes

R as a Calculator

Practice Part a

We can use R to find 2+7-3*5. Run the code chunk below to see if it works:

2+7-3*5
## [1] -6

You should get -6.

Pratice Part b

Next, insert write into the following the code needed to (25.5-20.2)/3:

Practice Part c

Next, insert your own code chunk below and write into it the code needed to produce the 12 squared plus 10 squared.

Practice Part d

Finally, insert your own code chunk and put write into it one line of code that does all of the following:

  • squares 3.1, then divides it by 25
  • squares 5.2, then divides it by 36
  • adds the previous two results together
  • then takes the square root of the result

Data Frames

Practice Part 1

Run the following code chunk to learn about m111survey:

data(m111survey)
View(m111survey)
help(m111survey)

How many students took part in this survey?

Practice Part b

Is fastest a numerical variable or a factor variable?

Is seat a numerical variable or a factor variable?

Practice Part c

How many students did not answer the question about their ideal height?

Making Lists with R

Practice Part a

In the following code chunk, insert the code needed to make a list of 100 fives.

Practice Part b

In the following code chunk, insert the code needed to make a list of all the numbers from 100 to 220, going up in steps of 10.