Question: Using R programming language, use R-Studio to create a matrix that records taking three trips in your car where each trip has a row name
Using R programming language, use R-Studio to create a matrix that records taking three trips in your car where each trip has a row name of the destination. The columns of the matrix should indicate the miles you drove, the number of gallons of gas used and the cost of gas per gallon. Label these appropriately. Enter some numbers that you feel are reasonable for each of the three trips. Now calculate:
- The total cost of each trip.
- The total distance for the three trips.
- The average distance on the three trips.
- The average cost per gallon of gas for the three trips.
- The cost per mile for the three trips.
- Convert the miles in your matrix to kilometers (1 mile = 1.67 kilometers) using matrix multiplication. (Hint: build a matrix that only changes the miles column.)
We can convert categories to numeric values using factors. This allows us to place categorial data into a matrix. Create the matric as above with 7 trips and add a categorical variable which indicates if the trip was highway, city, or mixed using factors. You can make these factors ordered based on expected fuel economy if you like. This is not real data, but if it were could you write a function to determine which type of trip has the best fuel economy?
Step by Step Solution
There are 3 Steps involved in it
To tackle this problem using R and RStudio well create a ma... View full answer
Get step-by-step solutions from verified subject matter experts
