Question
B. Suppose you are tasked with computing the precise dosage amounts of a certain drug in a collection of hypothetical scientific experiments. These amounts depend
B. Suppose you are tasked with computing the precise dosage amounts of a certain drug in a collection of hypothetical scientific experiments. These amounts depend upon some predetermined set of dosage thresholds (lowdose, meddose, and highdose), as well as a predetermined dose level factor vector named doselevel. Look at the following items (iiv) to see the intended form of these objects. Then write a set of nested if statements that produce a new numeric vector called dosage, according to the following rules:
First, if there are any instances of "High" in doselevel, perform the following operations: * Check if lowdose is greater than or equal to 10. If so, overwrite lowdose with 10; otherwise, overwrite lowdose by itself divided by 2. * Check if meddose is greater than or equal to 26. If so, overwrite meddose by 26. * Check if highdose is less than 60. If so, overwrite highdose with 60; otherwise, overwrite highdose by itself multiplied by 1.5. * Create a vector named dosage with the value of lowdose repeated (rep) to match the length of doselevel. * Overwrite the elements in dosage corresponding to the index positions of instances of "Med" in doselevel by meddose. * Overwrite the elements in dosage corresponding to the index positions of instances of "High" in doselevel by highdose.
Otherwise (in other words, if there are no instances of "High" in doselevel), perform the following operations: * Create a new version of doselevel, a factor vector with levels "Low" and "Med" only, and label these with "Small" and "Large", respectively (refer to Section 4.3 for details or see ?factor). Conditions and Loops 191 * Check to see if lowdose is less than 15 AND meddose is less than 35. If so, overwrite lowdose by itself multiplied by 2 and overwrite meddose by itself plus highdose. * Create a vector named dosage, which is the value of lowdose repeated (rep) to match the length of doselevel. * Overwrite the elements in dosage corresponding to the index positions of instances of "Large" in doselevel by meddose. Now, confirm the following:
i. Given lowdose dosage [1] 10.0 60.0 60.0 60.0 10.0 25.3 25.3
ii. Using the same lowdose, meddose, and highdose thresholds as in (i), given doselevel dosage [1] 25.0 25.0 25.0 83.4 25.0 83.4 83.4 Also, doselevel has been overwritten as follows: R> doselevel [1] Small Small Small Large Small Large Large Levels: Small Large
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started