Search for question
Question

#Homework

#Answer the following questions.

#Write your code in R.

#Run the code to see it really works.

# For this assignment, you will use a built-in dataset already stored in R called "mtcars"

# This is about Motor Trend Car Road Tests.

#First run the following two lines of code to load the dataframe into memory.

# Name of the dataframe is mtcars.

data("micars")

View(mtcars)

#1) List miles per galon (mpg) of the cars from 3rd car to 5th car.

#2) List number of cylinders (cyl), horsepower(hp), and number of gears (gear) for cars 11

through 15.

#3) List the weight(wt), cylinder (cyl) and gear of the 1st, 10th, and 15th cars.

#4) If gasoline per gallon costs $3.65, calculate the total cost of traveling 250 miles

# for the first 10 cars. HINT: First, calculate the gallons spent to travel 250 miles using mpg

column.

#5) List hp and qsec of all 5-gear cars.

#6) List all columns of cars whose mpg is less than or equal to 20,

# cyl is greater than 4, and hp is less than or equal to 150.

#7) List all columns of cars whose carb is not 1, wt is less than 3.2

# and disp is greater than 200.

#8) List all columns of cars whose carb is 2 or 4.

#9) Which of the following has a higher average mpg: Cars with 4 cylinders,

# or cars with 6 cylinders?

Fig: 1