Question

write code in R that does the following:

• step 1. initialize a vector for 500 numbers. • step 2. Then use R to sample 5 values from U(0,5), a uniform distribution wi

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

# Step 1: Initialize a vector for 500 numbers u=vector(numeric,500) # Step 2: Then use R to sample 5 values from U(0,5). Sa#Step 4: Take the average of your vector ave=mean (u) ave # Round your average into 4 digit **{r} C=round(ave, 4) [1] 2.4742

The program is done in R studio.

The r Code will be

u=vector('numeric',500)

s=runif(5,0,5)
s
u[1]=mean(s)
u[1]

for(i in 1:500)
{
s=runif(5,0,5)
u[i]=mean(s)
}

ave=mean(u)
ave

c=round(ave,4)
c

If you are satisfied please rate the answer.

Add a comment
Know the answer?
Add Answer to:
write code in R that does the following: • step 1. initialize a vector for 500...
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
  • I need help with part g. Use R • step 1. initialize a vector for 500...

    I need help with part g. Use R • step 1. initialize a vector for 500 numbers. • step 2. Then use R to sample 5 values from U(0,5), a uniform distribution with min=0 and max=5. Save the average of these uniform numbers into one of the elements of this vector. • Repeat step 2 500 times in a loop until you've filled up your vector. • Finally, take the average of your vector (the average of the 500 averages)!...

  • Step 1. Start Netbeans and create a project called ArrayLab Step 2. Write the main method...

    Step 1. Start Netbeans and create a project called ArrayLab Step 2. Write the main method  Declare and initialize an array called myNums int myNums = {3, 8, 12, 4, 2, 9, 6};  Declare an int called largestNum and set it to 0.  Write a for loop that prints the array for (int index = 0; index < myNums.length; index++) { System.out.println(myNums[index] + “ “); }  Write a for loop that prints the array backwards ...

  • MATLAB: Write a code using loop for which implements the following algorithm for finding the maximal...

    MATLAB: Write a code using loop for which implements the following algorithm for finding the maximal element in a vector (without using the ready Matlab function max): 1) Assume the first element of the vector to be the maximal one and assign its value to MyMax. 2) Take the second number and compare with the current maximum. If the second number is bigger, assign it as the new maximum, otherwise keep the old max as reference. 3) Take the third...

  • Create a program that creates an array of 500 random numbers between -10 and 10. Write...

    Create a program that creates an array of 500 random numbers between -10 and 10. Write several functions: Function 1 - prints the array with a certain number of elements per line. Prototype: void printArray(int array[], int numElements, int numPerLine, ostream &os) Function 2 prints only the array elements that are evenly divisible by an input number. Prototype: void printDivBy(int array[], int numElements, int numPerLine, int divBy, ostream &os) Function 3 takes the input array and returns the maximum, the...

  • Assignment • No variables declared after you start writing code, must be declared at the top....

    Assignment • No variables declared after you start writing code, must be declared at the top. • Reuse all the variables from the first half in the second half, do not make up new variable names. • You code must be properly formatted. • You must use the code provided and variables names provided and not add any more variables to your code. • No for(int I = 0; … no declaring variables except at top of code. • You...

  • Write MIPS code, please. Following: Write a program to be used by the Wisconsin DNR to...

    Write MIPS code, please. Following: Write a program to be used by the Wisconsin DNR to track the number of Deer Hunting Licenses issued in a county and the state. It will display a menu with 5 choices numbered 1-5. They are (1) update the count, (2) display the number of licenses already issued to a county whose number is input, (3) display the county number and the number of licenses already issued to a range of counties whose starting...

  • In C language The project should create a code maker. The computer version of this game...

    In C language The project should create a code maker. The computer version of this game uses digits 0-9 for the code. The feedback may be an array of characters using ‘b’ for black and ‘w’ for white. 1. The program should generate a code i. First, generate random number from 0 to 9. Actually, generate 4 random numbers ii. If any random number is repeated, replace the repeated number iii. Loop step ii until there is no repetition 2....

  • I am given an input file, P1input.txt and I have to write code to find the...

    I am given an input file, P1input.txt and I have to write code to find the min and max, as well as prime and perfect numbers from the input file. P1input.txt contains a hundred integers. Why doesn't my code compile properly to show me all the numbers? It just stops and displays usage: C:\> java Project1 P1input.txt 1 30 import java.io.*; // BufferedReader import java.util.*; // Scanner to read from a text file public class Project1 {    public static...

  • In this problem you'll get to use one of Java's random number generators, java.util.Random (see the...

    In this problem you'll get to use one of Java's random number generators, java.util.Random (see the docs for Random). This class generates a random double precision number uniformly distributed in the range [0.0 ... 1.0). That is, the numbers go from 0 to 1, including 0 but excluding 1. It is a common need in Java programming to generate a random integer number that's uniformly distributed in the range of [0 ... n), such as we saw in the dice...

  • Step 1. Write a program in assembly language (using macros) to print out the following messages...

    Step 1. Write a program in assembly language (using macros) to print out the following messages on the screen [20 marks]: Hello, programmers! Welcome to the world of, Linux assembly programming! Step 2. Write a C function to passed two numbers to the function and calculate the sum of all the numbers between them (both inclusive). [50 marks] a. Make a version with for loop b. Make a version with while loop c. Make a version with do.. while loop...

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