Answered step by step
Verified Expert Solution
Link Copied!

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 1 to 51. At the end of the loop, your code should produce the final message "The product of all odd numbers between 1 and 51 is x", where x is your answer.
B. Write a for loop that counts the number of negative numbers in a list of 5000 random numbers between -1 and 1, generated by the runif command. Use an if/else command in the loop to count "+1" 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 Z", where Z is the number of negative numbers.
C. Repeat the previous step, except compute the number of negative numbers in 2000 randomly generated vectors, each of which contains 5000
numbers. As part of this process your code should create a vector with 2000 elements, each of which is the # of negative numbers in one of
the randomly generated 5000-element vectors. Use the mean command to find the average number of negative numbers in the 2000 vectors.
Your code should end with the sentence "The average number of negative numbers in the 2000 random vectors is Z", where Z 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.R allows for a much faster way to count the number of elements ina vector that satisfy a certain condition. If myvector is your 5000
element vector of random numbers, the command sum (myvector 0) will count the number of elements less than 0. Use this fact to modify your code from the previous step so that you only use ONE for loop. But this time, generate 10000 random vectors, each with 10000 elements. Assign the name numnegs to the 10000 element vector that contains the number of negative numbers found in each of the 10000 randomly generated vectors of 10000 numbers between -1 and 1.
image text in transcribed

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_2

Step: 3

blur-text-image_3

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

Objects And Databases International Symposium Sophia Antipolis France June 13 2000 Revised Papers Lncs 1944

Authors: Klaus R. Dittrich ,Giovanna Guerrini ,Isabella Merlo ,Marta Oliva ,M. Elena Rodriguez

2001st Edition

3540416641, 978-3540416647

More Books

Students also viewed these Databases questions