Question: Option A: One important tool we haven't covered yet is a loop, such as a for-loop. In such a loop, R will iterate over

Option A: One important tool we haven't covered yet is a loop, such as a for-loop. In such a loop, R will iterate over 

Option A: One important tool we haven't covered yet is a loop, such as a for-loop. In such a loop, R will iterate over the values of an object using a counter. This is really helpful when you want to do something over and over again. Create a notebook with an R-cell in it where you can answer these questions. When answering, include your code and the output (a) (2 points) Create a character vector called pr which stores the names of all the provinces in Canada. Then, create a second vector called pop which stores the population of each province in pr. You might want to look this up on Statistics Canada's website! (b) (2 points) In a for-loop, the syntax looks like: for (COUNTER in LIST) { } do stuff to (COUNTER) The object COUNTER is a variable which the loop runs over, and LIST is a vector-like object that can be counted over. For example, try the code: numbers c(2,3,4,6) item 0 for (n in numbers) { print (n) item item + 1 print (item) } What does it do? (c) (2 points) Now, use a for-loop to print out the name of each province. (d) (4 points) In R, you can combine two pieces of text together with the with paste() command: n1 print (paste ("The number is:", n, "Wow!")) Using the paste() command and a for-loop print out the name and population of each province in a single line like: The population of Manitoba is 1,420,228

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!