Question

Using R, write a function called my_ifelse() that implements a vector form of the if-else statement...

Using R, 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.

Basically: make a function that does what the ifelse does. Thx!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Function :

my_ifelse(test , yes, no)  

{

If( test[i] == true)

{ printf("yes") ; }

else

{ print ("No"); }

}

Add a comment
Know the answer?
Add Answer to:
Using R, write a function called my_ifelse() that implements a vector form of the if-else statement...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • R programming 1. Write an assignment statement to complete each of the following without using diff()...

    R programming 1. Write an assignment statement to complete each of the following without using diff() and sign(): (a) generate a vector of the difference between the ith element and the (i+1)th element in a vector v of integers, where i = 1: length(v), and (b) generate a vector of the sign of each elements in the vector generated in (a) as follows: ‘p’ for positive, ‘n’ for negative. (Use v ⟵ c(1,4,7,2,1) for testing.) 2. Write a function that...

  • Use Mat Lab to write a function called forwarddiff.m that takes data sample locations and function...

    Use Mat Lab to write a function called forwarddiff.m that takes data sample locations and function samplings at those locations as inputs and returns an approximation of the derivative at the sample points based on forward finite difference method with order of accuracy O(h^3). The function should display nothing to the screen unless an error or warning occurs. The detailed specification is as follows: The approximation of derivative by forward difference method (for O(h^3) is given as: f' (x_1) =...

  • using java //HINT: Each function can be completed using a single statement. public class LinkListStack<T> implements...

    using java //HINT: Each function can be completed using a single statement. public class LinkListStack<T> implements StackADT<T> Unordered LinkedList<T> stack = new UnorderedLinked List: public void push(T element) //TODO-Write Code Here } public T popo //TODO - Write Code Here 3 public T peek) [ //TODO - Write Code Here ] public boolean isEmpty //TODO - Write Code Here 3 public int size) I/TODO - Write Code Here

  • Using Racket Recursion, tail-recursion, high-order functions and functional programming. 1. Modify our filter function so that...

    Using Racket Recursion, tail-recursion, high-order functions and functional programming. 1. Modify our filter function so that it is tail-recursive. You may use the letrec form but do not use any additional forms and functions besides those we've talked about in class. (define filter (lambda (input-list func)     (cond ((null? input-list) '())           ((func (car input-list))            (cons (car input-list) (filter (cdr input-list) func)))           (else            (filter (cdr input-list) func))))) 2. Test your filter function on '(25 -22 44 56...

  • Using propositional logic, write a statement that contains the propositions p, q, and r that is...

    Using propositional logic, write a statement that contains the propositions p, q, and r that is true when both p → q and q ↔ ¬r are true and is false otherwise. Your statement must be written as specified below. (a) Write the statement in disjunctive normal form. (b Write the statement using only the ∨ and ¬ connectives.

  • Python Programming assignment : Function of Q3: def isPositive(n): if(n>=0): return True else: return False Write...

    Python Programming assignment : Function of Q3: def isPositive(n): if(n>=0): return True else: return False Write a code for function main, that does the following: -creates a variable and assigns it the value True. - uses a while loop which runs as long as the variable of the previous step is True, to get a number from the user and if passing that number to the function of Q3 results in a True value returned, then add that number to...

  • Python Programming assignment : Function of Q3: def isPositive(n): if(n>=0): return True else: return False Write...

    Python Programming assignment : Function of Q3: def isPositive(n): if(n>=0): return True else: return False Write a code for function main, that does the following: -creates a variable and assigns it the value True. - uses a while loop which runs as long as the variable of the previous step is True, to get a number from the user and if passing that number to the function of Q3 results in a True value returned, then add that number to...

  • In a file named LLBag.java, write a class called LLBag that implements the Bag interface using...

    In a file named LLBag.java, write a class called LLBag that implements the Bag interface using a linked list instead of an array. You may use a linked list with or without a dummy head node. Bag interface code: /* * Bag.java * * Computer Science 112, Boston University */ /* * An interface for a Bag ADT. */ public interface Bag { /*    * adds the specified item to the Bag. Returns true on success    * and...

  • Using the R language: Suppose we have a vector, called longvector with 1000 elements. A. How...

    Using the R language: Suppose we have a vector, called longvector with 1000 elements. A. How would you let R calculate the mean value of longvector? Write the code here: B. What if there are some NA values and you'd like R to remove the NA values when calculating the mean of longvector? Write the code here: C. How would you plot a histogram to show the distribution of values in longvector? Write the code here: D. How would you...

  • Using python, create a program using nested loops to write a function called substring(s,b) that returns...

    Using python, create a program using nested loops to write a function called substring(s,b) that returns True or False depending on whether or not b is a substring of s. For example: String: "Diamond" Substring: "mond" The code will then state that this is true and "mond" is a substring of "Diamond". Example of what the program should output: Enter string: Tree Enter substring: Tre Yes, 'Tre' is a substring of 'Tree' Limitation: This program cannot use "find()" and "in"...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT