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....
let us create a variable for a row vector a = [1, 4, 1, 3, 2,...
let us create a variable for a row vector a = [1, 4, 1, 3, 2, 5, 0] and calculate the mean value of its elements using the Matlab function ‘mean’ and store this value in variable aMean. Fig. 1 gives the Matlab code to do this. a = [1, 4, 1, 3, 2, 5, 0]; aMean = mean(a); Figure 1: Matlab code – row vector and mean of its elements. Let us now construct a row vector b that...
Using R statistical software (a) Generate n = 100 observations from following time series model xt...
Using R statistical software (a) Generate n = 100 observations from following time series model xt =2cos(2πt/4)+ωt, where ωt is i.i.d N(0,1). (b) Apply the moving average to xt and get time series yt, such that yt = (xt + xt−1 + xt−2 + xt−3)/4. [hint: Use filter(x,rep(1/4,4)),sides=1] (c) Plot xt as a line and superimpose yt as a dashed line. (d) Describe the relationship between xt and yt.
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 an approximately equal number of loop iterations. The only OpenMP directive you are allowed to use is:...
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...
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 an approximately equal number of loop iterations. The only OpenMP directive you are allowed to use is:...
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...
Examination 1 Directions: All work MUST be done in Jupyter Notebook 1.Separate the following data into...
Examination 1 Directions: All work MUST be done in Jupyter Notebook 1.Separate the following data into input and output data: data = ([2,6,8], [4,32,12], [1,5,5]]) 2.Split into train and test data. Split the following dataset at the split point of 2 and using all columns: data = ([5, 10, 15], [20,25,30], [35,40,45]]) 3.Use the size of the dataset array dimensions in the shape dimension by specifying the parameters: data = [[2,4], [6,8], [10,12]] 4.Add the following arrays: A = array...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT