Assessment --- loops and multiple file processing in R

Sep 29, 2014 • François Michonneau

This is based on this lesson: https://github.com/swcarpentry/bc/blob/master/novice/r/03-loops-R.Rmd

Question 1

Given the following loop:

`
vehicle <- c(“Atlantis”, “Endeavour”)
countdown_length <- c(5, 3)</p>

for (i in seq_along(vehicle)) {
  for (j in (countdown_length[i]:0)) {
   cat(vehicle[i], j, "n")
  }
}
` What is the correct output? `
a.

Atlantis 3
Atlantis 2
Atlantis 1
Atlantis 0
Endeavour 5
Endeavour 4
Endeavour 3
Endeavour 2
Endeavour 1
Endeavour 0

b.
Endeavour 3
Endeavour 2
Endeavour 1
Endeavour 0
Atlantis 5
Atlantis 4
Atlantis 3
Atlantis 2
Atlantis 1
Atlantis 0

c.
Atlantis 5
Atlantis 4
Atlantis 3
Atlantis 2
Atlantis 1
Atlantis 0
Endeavour 3
Endeavour 2
Endeavour 1
Endeavour 0

d.
Endeavour 5
Endeavour 4
Endeavour 3
Endeavour 2
Endeavour 1
Endeavour 0
Atlantis 3
Atlantis 2
Atlantis 1
Atlantis 0
` * * * **Question 2** Given a folder that contained a lot of CSV files, use a for loop to return a vector that contains the number of rows in each file. The vector should be named with the file names.