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:
Copy and paste all the questions in the lab to the R script file and save the R script file point
Comment out all the questions point
Submit the compiled file. Follow this to learn how to compile your R script 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 headmtcars first, then headmyCars after creating the new object.
Step : Which car has the best hp hp stands for horse power
# What is the highest hpThe highest hp is
# Which car has the highest hp
Step : Explore mpg mpg stands for miles per gallon
# What is the highest mpg
# Which car has the highest mpgToyota Corolla has the highest mpg
# Create a sorted dataframe, based on mpg
# sort the dataframe by mpg in descending order, and store the sorted dataframe in 'myCarssorted'
Step : Which car has the best combination of mpg and hp
HINT: divide the mpg value by hp and pick the car with highest result
# 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$mpgmyCars$hp
# to find the maximum of this new created column
maxmyCars$efficiency
# Which car has the best combination of mpg and hp
# get the index of maximum efficiency first, and then get its row name
row.namesmyCarswhichmaxmyCars$efficiency
Step : 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:
scalemyCars$mpg
# scale hpscale is subtracting its column mean and then dividing its columns standard deviation. But you just use scale function like this:
scalemyCars$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 scalemyCars$mpg scalemyCars$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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
