Load data in the workspace by executing:

source("http://www3.nd.edu/~steve/computing_with_data_2014/7_Loops_etc/work_along_data_S7.R")

Compute a sequence r of length 100 such that r[1] = 0, and r[i+1] is randomly sampled from a normal distribution with mean r[i] and standard deviation 1. Inspect the first 5 entries and the last 5 entries. Any patterns?

r <- numeric(100)
r[1] <- 0
for (i in 2:100) {
  r[i] <- rnorm(1, r[i - 1], 1)
}
head(r, n = 5)
## [1]  0.0000000 -0.9707701 -0.9019612 -0.5487872  0.1724308
tail(r, n = 5)
## [1] 5.443355 2.919855 4.001404 5.264163 4.905254

Based on the above inspection of the first 5 entries and the last 5 entries, the last 5 entries continue to become more negative. Each entry is within the specified standard deviation of 1.

prob_L is list of character vectors. Use a for loop to define a vector p1 such that p1[j] is the first entry of the jth component of prob_L.

p1[j] should be a vector of the first entries.

N <- length(prob_L)
p1 <- character(N)
for (j in 1:N) {
  p1[j] <- prob_L[[j]][1]
}
p1
## [1] "word"  "A"     "8"     "FALSE" "yes"

Create a vector where the j−entry is the second entry of the jth component of prob_L

p2 should be a vector of all of the second entries

N <- length(prob_L)
p2 <- character(N)
for (j in 1:N) {
  p2[j] <- prob_L[[j]][2]
} 
p2
## [1] "word2" "2"     NA      NA      "no"