Question

Using R and install.packages("MASS"), library(MASS) 1. Generate the following vector using at least two methods. 0,...

Using R and install.packages("MASS"), library(MASS)

1. Generate the following vector using at least two methods.

0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4

2. Generate the following vector.

Apple1, Banana2, Orange3, Cranberry4, Watermelon5

3. Generate the following vector using the “rep” function.

a, a, b, b, c, c, a, a, b, b, c, c

4. In vector y = (8, 3, 5, 7, 6, 6, 8, 9, 2, 3, 9, 4, 10, 4, 11), which elements of y contains values bigger than 5? Select those elements.

5. Generate a 3 by 4 matrix.

6. Generate a list of 4 elements of difference class type.

7. data(Cars93) in the “MASS” package contains data on 93 makes of car sold in the USA.

   The Type variable classifies the type of market the car is aimed at. Find the cheapest car in each type, and the car with the greatest fuel efficiency.

Compute the mean horsepower for each type.

8. The data set DDT in the “MASS” contains independent measurements of the pesticide DDT on kale. Make a histogram and a boxplot of the data. From these, estimate the mean and standard deviation. Check your answers with the appropriate functions.

Homework Answers

Answer #1

### ques 1
seq(0,4,0.5)
x=0
for (i in 1:8) {

x[i+1]=x[i]+0.5
}
x

#### ques 2
fruit=c("Apple1", "Banana2", "Orange3", "Cranberry4", "Watermelon5")
fruit
###### ques 3
c(rep("a",2),rep("b",2),rep("c",2),rep("a",2),rep("b",2),rep("c",2))

#####ques 4
y = c(8, 3, 5, 7, 6, 6, 8, 9, 2, 3, 9, 4, 10, 4, 11)
which(y>5)

# ans  1  4  5  6  7  8 11 13 15

######ques 5
matrix(0,3,4)

   [,1] [,2] [,3] [,4]
[1,]    0    0    0    0
[2,]    0    0    0    0
[3,]    0    0    0    0
Know the answer?
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
Similar Questions
Using R programming language, complete the following. 1. Generate the bivariate normal sample of size 100...
Using R programming language, complete the following. 1. Generate the bivariate normal sample of size 100 with parameters a. marginal mean of X equal to 1, b. marginal mean of Y equal to 2, c. marginal variance of X equal to 3, d. marginal variance of Y equal to 4, e. correlation between X and Y equal to -1/2. You can use the function mvrnorm(), first installing its package by the code if (! require ("MASS")) install.packages("MASS"); library ("MASS") 2....
For this assignment you need to write a parallel program in C++ using OpenMP for vector...
For this assignment you need to write a parallel program in C++ using OpenMP for vector addition. Assume A, B, C are three vectors of equal length. The program will add the corresponding elements of vectors A and B and will store the sum in the corresponding elements in vector C (in other words C[i] = A[i] + B[i]). Every thread should execute approximately equal number of loop iterations. The only OpenMP directive you are allowed to use is: #pragma...
1. A plane curve has been parametrized with the following vector-valued function, r(t) = (t +...
1. A plane curve has been parametrized with the following vector-valued function, r(t) = (t + 2)i + (-2t2 + t + 1)j a. Carefully make 2 sketches of the plane curve over the interval . (5 pts) b. Compute the velocity and acceleration vectors, v(t) and a(t). (6 pts) c. On the 1st graph, sketch the position, velocity and acceleration vectors at t=-1. (5 pts) d. Compute the unit tangent and principal unit normal vectors, T and N at...
C++ Code! Represent the following matrix using a two-dimensional array and write a nested for loop...
C++ Code! Represent the following matrix using a two-dimensional array and write a nested for loop to initialize the elements (do not initialize the array in the declaration): 10  9   8 7   6   5 4 3   2
Use R to do each of the following. Use R code instructions that are as general...
Use R to do each of the following. Use R code instructions that are as general as possible, and also as efficient as possible. Use the Quick-R website for help on finding commands. 1. Enter the following values into a data vector named Dat: 45.4 44.2 36.8 35.1 39.0 60.0 47.4 41.1 45.8 35.6 2. Calculate the difference between the 2nd and 7th entries of this vector using only reference indices. 3. Calculate the median of Dat. 4. Sort the...
For the following set of data, X Y 1 0 2 2 3 4 4 6...
For the following set of data, X Y 1 0 2 2 3 4 4 6 5 8 a. Compute the Pearson correlation, r, for this data set. b. Re-arrange the Y scores so that the value of r = –1.00.
Consider the following data set consisting of two variables: x 0 3 5 6 8 y...
Consider the following data set consisting of two variables: x 0 3 5 6 8 y 10 9 7 4 1 (a) Draw a scatter diagram of the data. (b) Compute the correlation coecient r. (c) Is there a linear relation between x and y that you are condent about? If so, in what direction? Justify your answer.
For each of the following joint probability mass functions, make a table, find the two marginal...
For each of the following joint probability mass functions, make a table, find the two marginal mass functions, and decide whether X and Y are independent. (In every case the mass function is defined to be 0 at values of x and y not specified.) a. p(x, y) = 1 36 if both x and y are in the set {1, 2, 3, 4, 5, 6}. b. p(x, y) = x 2y 84 for x = 1, 2, 3 and...
1) Answer the questions using the following data. A : 4, 7, 5, 3, 3, 6...
1) Answer the questions using the following data. A : 4, 7, 5, 3, 3, 6 B : 8, 12, 9, 2, 10, 15 a. Calculate the mean and the standard deviation. b. Calculate the coefficient of variation. c. Compute the z-score of all data. d. Detect an outlier using the z-score.
5) Here are some (simulated) data on the maximum age distribution in rabbits: age: 0 1...
5) Here are some (simulated) data on the maximum age distribution in rabbits: age: 0 1 2 3 4 5 6 7 8 9 frequency: 47 232 429 388 205 99 58 10 3 0 Give the following: a) Pr(Y > 6) b) Pr(2 < Y < 6) c) Pr(Y ≥ 3) d) Pr(Y < 7) e) Pr(Y = 9) e) Add (a) and (d). Are you surprised? Why or why not?