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.
### 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
Get Answers For Free
Most questions answered within 1 hours.