Answered step by step
Verified Expert Solution
Question
1 Approved Answer
A . Write a for loop that computes the product of all odd RStudio programming beginner level, please help!numbers from 1 to 5 1 .
A Write a for loop that computes the product of all odd RStudio programming beginner level, please help!numbers from to At the end of the loop, your code should produce the final message "The product of all odd numbers between and is where is your answer.
B Write a for loop that counts the number of negative numbers in a list of random numbers between and generated by the runif command. Use an ifelse command in the loop to count when number is negative and does not count if the number is nonnegative.
Your code for this part should end with the text "The number of negative numbers is where is the number of negative numbers.
C Repeat the previous step, except compute the number of negative numbers in randomly generated vectors, each of which contains
numbers. As part of this process your code should create a vector with elements, each of which is the # of negative numbers in one of
the randomly generated element vectors. Use the mean command to find the average number of negative numbers in the vectors.
Your code should end with the sentence "The average number of negative numbers in the random vectors is where is the average. You will need a for loop outside of the for loop
from the previous step. This is called a nested for loop. What number is closest to your average? Is it what you expected?
D allows for a much faster way to count the number of elements ina vector that satisfy a certain condition. If myvector is your
element vector of random numbers, the command sum myvector will count the number of elements less than Use this fact to modify your code from the previous step so that you only use ONE for loop. But this time, generate random vectors, each with elements. Assign the name numnegs to the element vector that contains the number of negative numbers found in each of the randomly generated vectors of numbers between and
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