Question

Assume you have a list L whose members are different stock values. Write a function in...

  1. Assume you have a list L whose members are different stock values.
    1. Write a function in R with one parameter X that will return “S” if the number is bigger than X and “B” otherwise
    2. Apply this function to each member of the list
    3. How can you modify this function so that will accept sequence in its parameter?
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please find the Code below

______________________

a. function is written with name check_boundary

b. Below is the code to apply the function to each member of the list


L <- list(2,4,5,6,7,8,4,3)
X <- 5
check_boundary <- function(arg_1,X) {
if(arg_1 > X){
print("S")
}else{
print("B")
}
}
for(val in L){
check_boundary(val,X)
}

Output

______

I.lı Result $Rscript main.r [1 B [1 B [1 B [1 S [1 S [1 S [1 B [1 B

Modified Function so it will accept the sequence in its parameters

_____________________________________

X <- 5
check_boundary <- function(arg_1,X) {
for(val in arg_1){
if(val > X){
print("S")
}else{
print("B")
}
}
}
check_boundary(seq(2,10),X)

Output

______

I.lI Result $Rscript main.r [1 B [1 B [1 B [1 B [1 S [1 S [1 S [1 S

Add a comment
Know the answer?
Add Answer to:
Assume you have a list L whose members are different stock values. Write a function in...
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
  • In this problem, you should write one function named copy and increment. This function will have...

    In this problem, you should write one function named copy and increment. This function will have one parameter, which you can assume will be a list of integers. This function should return a copy of the parameter list, in which each number from the parameter list has been increased by 1. The function should not modify the values in the parameter list. For example, the code: values - 20, 40, 10, 60, 77, 2) other copy and incrementales) print values...

  • Assume that L is a list of Boolean values, True and False. Write a function longestFalse(L)...

    Assume that L is a list of Boolean values, True and False. Write a function longestFalse(L) which returns a tuple (start, end) representing the start and end indices of the longest run of False values in L. If there is a tie, then return the first such run. For example, if L is False False True False False False False True True False False 0 1 2 3 4 5 6 7 8 9 10 then the function would return...

  • Python 2.7 Write a function cumsum() that takes a list l as argument and returns the...

    Python 2.7 Write a function cumsum() that takes a list l as argument and returns the cumulative sum (also known as the prefix sum) of l, which is a list, say cs of the same length as l such that each element cs[i] is equal to the sum of the first i + 1 elements of l, i.e., cs[i] == l[0] + l[1] + l[2] + ... + l[i] You should not modify the argument list l in any way....

  • write the following code in python 3.2+. Recursive function prefered. Thank you! Define a function named...

    write the following code in python 3.2+. Recursive function prefered. Thank you! Define a function named q3() that accepts a List of characters as a parameter and returns a Dictionary. The Dictionary values will be determined by counting the unique 3 letter combinations created by combining the values at index 0, 1, 2 in the List, then the values at index 1, 2, 3 and so on. The q3() function should continue analyzing each sequential 3 letter combination and using...

  • Assignment 5 Class For Basic Complex Number Operations 1. A complex number is of the form...

    Assignment 5 Class For Basic Complex Number Operations 1. A complex number is of the form a + ib. Let x = a +ib and y = c +id. The operation of adding two complex numbers is: x + y = (a + c)+i(b+d). The operation of subtracting two complex number is: x-y = (a -c)+i(b-d). The operation of multiplying two complex number is: xxy = (ac - bd) +i(bc + ad). The operation of dividing two complex number is:...

  • Q1)(20p)Write a static member function called removeLongestRepeatingSegment that takes a String a...

    Q1)(20p)Write a static member function called removeLongestRepeatingSegment that takes a String argument. The method will return a new String by removing the logest segment that contains consequtively repeating characters. public static void main(String []args){ String s=”1111222223333311111111444455552222”; String res= removeLongestRepeatingSegment(s); will return “11112222233333444455552222” } public static String removeLongestRepeatingSegment(String s){ --------------- Q2)15p)Given a list of objects stored (in ascending order) in a sorted linked list, implement member method which performs search as efficiently as possible for an object based on a key....

  • Python recursive function: Given an ordered list L. A permutation of L is a rearrangement of...

    Python recursive function: Given an ordered list L. A permutation of L is a rearrangement of its elements in some order. For example (1,3, 2) and (3, 2, 1) are two different permutations of L=(1,2,3). Implement the following function: def permutations (lst, low, high) The function is given a list 1st of integers, and two indices: low and high (lows high), which indicate the range of indices that need to be considered The function should return a list containing all...

  • Assume you have the following declarations: enum StudentType {BILL, JANE, MARY}; StudentType oneStudent; Write a function,...

    Assume you have the following declarations: enum StudentType {BILL, JANE, MARY}; StudentType oneStudent; Write a function, GetName, that will accept a string as a parameter and return the appropriate StudentType. Provide a main function demonstrating the GetName function in use.

  • write a Python function that takes in a list of integers and returns maximum and minimum values in the list as a tuple

    1 write a Python function that takes in a list of integers and returns maximum and minimum values in the list as a tuple. Hint (can be done in one pass, you are not allowed to use built-on min and max functions.)max, min = find_max_min(my_list):2 write a Python function that takes in a list of integers (elements), and an integer number (num). The functions should count and return number of integers in elements greater than, less than, and equal to...

  • Need help with this question. Write a function take first n that takes a list l...

    Need help with this question. Write a function take first n that takes a list l and an integer n as arguments. The function should return (as a new list) the first n values from the list. In the event that n is greater than the length of l , the entire list should be returned. I know this is correct thus far def take_first_n(l, n): return

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