In: Statistics and Probability
Need To Do this in R Studio...Here are the Instruction steps:
1. Using the 1:n construct, create the sequence 4,8,12, ...,
48.
2. Similarly, create the sequence 0,5,10,15, ..., 100.
3. Using a for() loop and the print() function, print the values
2,3,4,..., 7.
4. Using a for() loop and the print() function, print the values
8,11,14, ..., 26.
5. Create a vector with a length of 10. Then, using a for() loop,
assign the values
3,6,9, ..., 30. to the vector.
6. (a) Create a vector x, with a length of 100.
(b) Then simulate rolling a pair of dice 100 times.
To do this, you can use, within a for() loop, the code: x[i] <-
sample(c(1:6), 1, replace=T) + sample(c(1:6), 1, replace=T)
Each individual result will lie in the range 2--12.
Then, to see the distribution of your results, use the code:
table(x)
(The function table() will create a frequency table for
you)
Find the code below:
# Part (1)
(1:12)*4
# Part (2)
(0:20)*5
# Part (3)
for(i in 2:7){
print(i)
}
# Part (4)
for(i in 2:8){
print(3*i + 2)
}
# Part (5)
x = numeric(10)
for(i in 1:10){
x[i] = 3*i
}
x
# Part (6)
# (a)
x = numeric(100)
# (b)
for(i in 1:100){
x[i] = sample(c(1:6), 1, replace=T) + sample(c(1:6), 1, replace=T)
}
table(x)
Output:
.