Question: Learning Objectives This exercise contributes to the development of problem solving skills. After completing this exercise, students should understand how to manipulate the data to

Learning Objectives
This exercise contributes to the development of problem solving skills. After completing this exercise, students should understand how to manipulate the data to extract useful information from data and be able to perform mathematical calculations from a dataframe.
### Submission and grading policy:
1. Copy and paste all the questions in the lab to the R script file and save the R script file (1 point).
2. Comment out all the questions (1 point).
3. Submit the compiled file. Follow this to learn how to compile your R script (1 point):
Dataframes Doing Some Initial Data Analysis
Explore the "mtcars" dataset (which is already included in R). Copy the mtcars dataset into a new dataframe (called it myCars), so that if you mess up, you can start again (by copying mtcars into myCars again). Print head(mtcars) first, then head(myCars) after creating the new object.
Step 1: Which car has the best hp (hp stands for horse power)
# 1) What is the highest hp?(The highest hp is 335)
# 2) Which car has the highest hp?
Step 2: Explore mpg (mpg stands for miles per gallon)
# 3) What is the highest mpg?
# 4) Which car has the highest mpg?(Toyota Corolla has the highest mpg.)
# 5) Create a sorted dataframe, based on mpg
> # sort the dataframe by mpg, in descending order, and store the sorted dataframe in 'myCars_sorted'
Step 3: Which car has the best combination of mpg and hp?
HINT: divide the mpg value by hp, and pick the car with highest result
# 6) One method to pick an efficient car: divide the mpg value by hp, and pick the car with highest result
# add a new column 'efficiency' in the dataframe to store the division result
myCars$efficiency <- myCars$mpg/myCars$hp
# to find the maximum of this new created column
max(myCars$efficiency)
# 7) Which car has the best combination of mpg and hp?
# get the index of maximum efficiency first, and then get its row name
row.names(myCars)[which.max(myCars$efficiency)]
Step 4: Which car has best combination of mpg and hp, where mpg and hp must be given equal weight?
#### The goal of this step is to put you in a situation where you have to implement a new function you didn't learn. You should be able to use knowledge on R to solve new problem.
# scale 'mpg' by subtracting its column mean and then dividing the column standard deviation
#scale mpg first:
scale(myCars$mpg)
# scale 'hp'(scale is subtracting its column mean and then dividing its columns standard deviation. But you just use scale function like this:)
scale(myCars$hp)
# You just created two new variable using mpg and hp using scale function. Add the two scaled data and save the result as a new column 'combination' in the dataframe. Populate XXXX below;
myCars$XXXX <-scale(myCars$mpg)+ scale(myCars$hp)
# Get the index of maximum combination first, and then get its row name. HINT: use which.max function AND row.names function

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!