Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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 iii. Given lowdose dosage [1] 9 49 49 Also, doselevel has been overwritten as follows: R> doselevel [1] Small Large Large Levels: Small Large iv. Using the same lowdose, meddose, and highdose thresholds as (iii), as well as the same doselevel as (i), the result of dosage after running the nested if statements is as follows: R> dosage [1] 4.5 91.5 91.5 91.5 4.5 26.0 26.0 c. Assume the object mynum will only ever be a single integer between 0 and 9. Use ifelse and switch to produce a command that takes in mynum and returns a matching character string for all possible values 0, 1, . . . , 9. Supplied with 3, for example, it should return "three"; supplied with 0, it should return "zero". ANSWER IN R

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Logidata+ Deductive Databases With Complex Objects Lncs 701

Authors: Paolo Atzeni

1st Edition

354056974X, 978-3540569749

More Books

Students also viewed these Databases questions