Option A: One important tool we haven't covered yet is a loop, such as a for-loop....
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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 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
Expert Answer:
Related Book For
Posted Date:
Students also viewed these programming questions
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
Having read the material in Sentence-Level Stylistics, share the following: What was unsurprising? In other words, what did you know or suspect already that you already practice and find easy to...
-
Calculate the new profit sharing ratio after the admission of Fischer. Assignment Ubisoft Entertainment is a partnership of exclusive game distributors who specialize in electronic arts and play...
-
Repeat Exercise 1 using Simpson's rule. In Exercise 1 222% dx In x dx edx dx 2-4 dx X2-4 /4 sin x di ein 2r dx
-
The yield on the company's outstanding bonds is 7.75%, its tax rate is 25%, the next expected dividend is $0.65 a share, the dividend is expected to grow at a constant rate of 6.00% a year, the price...
-
During a quality assurance check, the actual weights (in kilograms) of eight sacks of cement were recorded as 20.5, 19.4, 19.6, 18.0, 21.0, 20.2, 20.4, and 20.9. (a) Find the mean and the median of...
-
Jessie Romero offered to deliver two trade- in vehiclesa 2003 Mitsubishi Montero SP and a 2002 Chevrolet Silverado pickupto Scoggin-Dickey Chevrolet Buick, Inc., in exchange for a 2006 Silverado...
-
The following information is taken from the partial trial balance of Ivanhoe Corporation for the year ended March 31, 2023: Accounts payable Accounts receivable $80,000 167,000 Accumulated...
-
The SD of a particular type of 10-mg tablets is 1 mg, while the SD of another type of 50-mg tablets is 2 mg. Which type of tablets has more variability?
-
Your next-door neighbors, Emma and Tom Alexander, came to you with a question: They want to buy stock in the 123 Company and noticed "Goodwill" on their balance sheet. How would you define "Goodwill"...
-
What is the deal?" is a company in West Windsor, NJ operated by Pam Smith. The company has two activities. Here are the facts: A. Subscriptions: The company provides maintenance of the equipment...
-
Use this lecture outline/guide to add notes from your reading under each topic. Include references to examples, exercises and problems that illustrate the concept. How is a predetermined overhead...
-
Long - term operating assets are recorded at their original purchase price plus any expenditures required to obtain and prepare the asset for its intended use. A company purchased land and a building...
-
Which age group generally benefits the most from the establishment of a cash balance pension plan? What is the contribution limit for money purchase pension plans? How are participant account...
-
The objective of this paper is to research complex accounting concepts in financial statement reporting, taxation, internal controls, XBRL, auditing, or ethics. Choose a topic that was discussed. A...
-
Test your confidence in the following Project Decisions: SI. # Question 01 02 03 04 05 06 07 08 09 10 How many years did it take to construct the largest Egyptian Pyramid- Pyramid of Cheops? When was...
-
The swinging spring is an example of a two degree-of-freedom system with a cubic nonlinearity. Indicate whether the statement presented is true or false. If true, state why. If false, rewrite the...
-
The period of free vibrations of a nonlinear system depends upon initial conditions. Indicate whether the statement presented is true or false. If true, state why. If false, rewrite the statement to...
-
A mass attached to a linear spring sliding on a surface with Coulomb damping is an example of a nonlinear system. Indicate whether the statement presented is true or false. If true, state why. If...
Study smarter with the SolutionInn App