please help by coding all parts for problems in R through RMarkdown The objective of this question
Fantastic news! We've Found the answer you've been seeking!
Question:
please help by coding all parts for problems in R through RMarkdown
Transcribed Image Text:
The objective of this question is to introduce the ifelse() function and give practice with vectorization. (a) Write a function called my _ifelse() that implements a vector form of the if-else statement without the ifelse() function. That is, the ith element of my ifelse (test, yes, no) will be yes [i] if test [i] is TRUE and no [i] if test [i] is FALSE. Values of yes or no should be recycled if either is shorter than test. Hint: This can be written as a loop, but a vectorized solution is better. (b) Verify that your my_ifelse() function works by executing the following commands: x < (1:10) pi my_ifelse(x %% 1 >= 0.5, x %/% 1 + 1, x %/% 1) (c) Use your my_ifelse() function to write my _abs() and my_sign() functions that, respectively, compute the absolute values and signs of the elements of a numeric vector. The respective outputs of my_abs (x) and my_sign() should be identical to abs(x) and sign(x) for any numeric vector x. Hint: It may be helpful to use my_abs () when writing my_sign(). The objective of this question is to introduce the ifelse() function and give practice with vectorization. (a) Write a function called my _ifelse() that implements a vector form of the if-else statement without the ifelse() function. That is, the ith element of my ifelse (test, yes, no) will be yes [i] if test [i] is TRUE and no [i] if test [i] is FALSE. Values of yes or no should be recycled if either is shorter than test. Hint: This can be written as a loop, but a vectorized solution is better. (b) Verify that your my_ifelse() function works by executing the following commands: x < (1:10) pi my_ifelse(x %% 1 >= 0.5, x %/% 1 + 1, x %/% 1) (c) Use your my_ifelse() function to write my _abs() and my_sign() functions that, respectively, compute the absolute values and signs of the elements of a numeric vector. The respective outputs of my_abs (x) and my_sign() should be identical to abs(x) and sign(x) for any numeric vector x. Hint: It may be helpful to use my_abs () when writing my_sign().
Expert Answer:
Posted Date:
Students also viewed these programming questions
-
Find a function (x, y) such that = (y, x).
-
Money Laundry has 10 washers and 15 dryers. All orders are first sent to wash and then to dry. It takes, on average, 30 minutes to wash one order and 40 minutes to dry. a. What is the capacity of the...
-
Explain the difference between the nature-of-expense and function-of-expense classifications.
-
When a borrower records an interest payment on an installment note, how are the balance sheet and income statement affected? AppendixLO1
-
Complete the 2019 federal income tax return for Sarah Hamblin. Be sure to include only required tax forms when completing the tax return. For purposes of this assignment, unless instructed otherwise,...
-
S-F:12-7 Journalizing bond transactions (Learning Objective 3) Owen Company issued a $110,000, 11%, 10-year bond payable at 94 on January 1, 2024. Interest is paid semiannually on January 1 and July...
-
Floyd's Bumpers has distribution centers in Lafayette, Indiana: Charlotte, North Carolina; Los Angeles, California; Dallas, Texas; and Pittsburgh, Pennsylvania. Each distribution center carries all...
-
Find dy/dx in terms of t if dy/dx = x = t-t, y=2-9t
-
Suppose that you are conducting a survey of adults and recording the number of books each individual read in the past year. The mean number of books is 12, and the standard deviation is 4. Allen...
-
Write a program to move a signed number from smaller register to bigger register. Hint: movzx ax, bl Topic: Data Related Operators and Directives in assembly language
-
Develop a plan to establish a strong credit history. lo1
-
E 12-1 1. What is a characteristic of a forward contract? a Traded on an exchange b Negotiated with a counterparty c Covers a stream of future payments d Must be settled daily
-
E 12-4 Accounting for foreign currencydenominated purchases Zip purchased merchandise from Tas of Japan on November 1, 2016, for 10,000,000 yen, payable on December 1, 2016. The spot rate for yen on...
Study smarter with the SolutionInn App