Name:
Andrew ID:
Collaborated with:

On this homework, you can collaborate with your classmates, but you must identify their names above, and you must submit your own homework as an knitted HTML file on Canvas, by Sunday 10pm, this week.

## For reproducibility --- don't change this!
set.seed(01302018)

Indexing, vectorization, and iteration practice

(x = runif(10, -1, 1))
##  [1] -0.5703595 -0.4517724  0.4088408 -0.1856029 -0.2185913 -0.2291011
##  [7] -0.3781738  0.7277174 -0.6395923 -0.9342617
# Increment the negative entries by 0.1

(y = sample(c(TRUE,FALSE), 8, replace=TRUE)) 
## [1]  TRUE FALSE  TRUE FALSE FALSE  TRUE  TRUE FALSE
# Replace the FALSE entries by NA

(z = c("Hey", "you", "there", "what's", "going", "on")) 
## [1] "Hey"    "you"    "there"  "what's" "going"  "on"
# Paste an exclamation mark "!" at the end of the entries with at most 3 characters
n = 10
x = runif(n) # Generate 10 numbers uniformly between 0 and 1
x = matrix(runif(40), 10, 4)
a = matrix(rnorm(15), 5, 3)
b = matrix(rnorm(12), 3, 4)
c = matrix(0, 5, 4)

Shakespeare’s complete works

On to the more fun stuff! As in lab, we’re going to look at William Shakespeare’s complete works, taken from Project Gutenberg. The Shakespeare data file is up on our course website, and to load it into your R session, as a string vector called shakespeare.lines:

shakespeare.lines =
  readLines("http://www.stat.cmu.edu/~ryantibs/statcomp-S18/data/shakespeare.txt")

Where are Shakespeare’s plays, in this massive text?

Extracting and analysing a couple of plays

Zipf’s law: amazing or what? (optional)