Question: ( More practice on the binary operators ) Prof. Lee is taking his friends and family to La Ronde, Montreal s iconic amusement park. The

(More practice on the binary operators) Prof. Lee is taking his friends and family to La Ronde, Montreals iconic amusement park. The heights of his group of 10 people, measured in centimeters, are recorded in the following vector:
heights = c(145.5,189.7,183,135.3,175,178,162,102,168.8,195.2)
Prof. Lees group is eager to ride the roller coaster, but theres a catch: only those whose height falls between 150 cm and 185 cm are allowed on the ride. With this heartbreaking news, answer the following questions:
To quickly determine who meets the height requirement, Prof. Lee decides to assign each person a unique English letter. In R, the LETTERS vector provides all the capital letters of the alphabet.
LETTERS
[1]"A""B""C""D""E""F""G""H" "I" "J""K""L""M""N""O""P""Q""R""S"
[20]"T""U""V""W""X""Y""Z"
Using LETTERS, find a simple way to assign "A" to "J"(in order) to each member of the group. So youll have to have the following:
heights
A B C D E F G H I J
145.5189.7183.0135.3175.0178.0162.0102.0168.8195.2
NOTE. Refrain from manually assigning characters to the group members one-by-one.
Next, we need to determine who is too tall, too short, or appropriately sized for the ride. Using appropriate binary operators, create a new vector named heights_eval. This vector should have the same indices as heights, with values assigned according to the following rules:
If the height is less than 150, assign short.
If the height is between 150 and 185(inclusive), assign pass.
If the height is greater than 185, assign tall.
The resulting vector should look like this:
heights_eval
[1] "short" "tall" "tall" "short" "pass" "pass" "pass" "short" "pass"
[10] "tall"
Hint. You can start creating a vector of length 10 and modify the values later. For example, heights_eval = rep(0,10) does the job.
By using the results from part (a) and (b), write a code that prints the names whose height is appropriate for the ride. So your code should print the following:
[1]"E""F""G" "I"
Instead of riding the roller coaster, Prof. Lees group decided to try a different attraction. Fortunately, everyone can take this ride, but the entrance fee varies based on height:
Heights below 150 cm: 3 CAD
Heights between 150 and 185 cm (inclusive): 4 CAD
Heights above 185 cm: 5 CAD
Using your solutions from parts (a) and (b), write a code that calculates and prints the total entrance fee Prof. Lees group has to pay.
[1]40
NOTE. Refrain from manually assigning entrance fee to the group members one-by-one.

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!