cars <- read.csv ('https://vincentarelbundock.github.io/Rdatasets/csv/DAAG/carprice.csv')

head(cars)
##    X    Type Min.Price Price Max.Price Range.Price RoughRange gpm100 MPG.city
## 1  6 Midsize      14.2  15.7      17.3         3.1       3.09    3.8       22
## 2  7   Large      19.9  20.8      21.7         1.8       1.79    4.2       19
## 3  8   Large      22.6  23.7      24.9         2.3       2.31    4.9       16
## 4  9 Midsize      26.3  26.3      26.3         0.0      -0.01    4.3       19
## 5 10   Large      33.0  34.7      36.3         3.3       3.30    4.9       16
## 6 11 Midsize      37.5  40.1      42.7         5.2       5.18    4.9       16
##   MPG.highway
## 1          31
## 2          28
## 3          25
## 4          27
## 5          25
## 6          25
  1. Use the summary function to gain an overview of the data set. Then display the mean and median for at least two attributes.
summary(cars)
##        X             Type             Min.Price         Price      
##  Min.   : 6.00   Length:48          Min.   : 6.90   Min.   : 7.40  
##  1st Qu.:17.75   Class :character   1st Qu.:11.40   1st Qu.:13.47  
##  Median :29.50   Mode  :character   Median :14.50   Median :16.30  
##  Mean   :36.54                      Mean   :16.54   Mean   :18.57  
##  3rd Qu.:60.25                      3rd Qu.:19.43   3rd Qu.:20.73  
##  Max.   :79.00                      Max.   :37.50   Max.   :40.10  
##    Max.Price      Range.Price       RoughRange         gpm100     
##  Min.   : 7.90   Min.   : 0.000   Min.   :-0.020   Min.   :2.800  
##  1st Qu.:14.97   1st Qu.: 1.700   1st Qu.: 1.705   1st Qu.:3.800  
##  Median :18.40   Median : 3.300   Median : 3.305   Median :4.200  
##  Mean   :20.63   Mean   : 4.092   Mean   : 4.089   Mean   :4.167  
##  3rd Qu.:24.50   3rd Qu.: 5.850   3rd Qu.: 5.853   3rd Qu.:4.550  
##  Max.   :42.70   Max.   :14.600   Max.   :14.600   Max.   :5.700  
##     MPG.city      MPG.highway   
##  Min.   :15.00   Min.   :20.00  
##  1st Qu.:18.00   1st Qu.:26.00  
##  Median :20.00   Median :28.00  
##  Mean   :20.96   Mean   :28.15  
##  3rd Qu.:23.00   3rd Qu.:30.00  
##  Max.   :31.00   Max.   :41.00
  1. Create a new data frame with a subset of the columns and rows. Make sure to rename it.
large_cars <- subset(cars, Type == 'Large')
head(large_cars)
##     X  Type Min.Price Price Max.Price Range.Price RoughRange gpm100 MPG.city
## 2   7 Large      19.9  20.8      21.7         1.8       1.79    4.2       19
## 3   8 Large      22.6  23.7      24.9         2.3       2.31    4.9       16
## 5  10 Large      33.0  34.7      36.3         3.3       3.30    4.9       16
## 13 18 Large      18.0  18.8      19.6         1.6       1.60    4.7       17
## 15 20 Large      18.4  18.4      18.4         0.0      -0.01    4.2       20
## 17 22 Large      29.5  29.5      29.5         0.0       0.02    4.3       20
##    MPG.highway
## 2           28
## 3           25
## 5           25
## 13          26
## 15          28
## 17          26
  1. Create new column names for the new data frame.
bigOlecars <- setNames(large_cars, c("Index", "Car_Type", "Minimum_Price", "Actual_Price", "Maximum_Price", "The_Range_Price", "The_Rough_Range", "G_P_M_100", "Miles_Per_Gallon_City", "Miles_Per_Gallon_Highway"))
bigOlecars
##    Index Car_Type Minimum_Price Actual_Price Maximum_Price The_Range_Price
## 2      7    Large          19.9         20.8          21.7             1.8
## 3      8    Large          22.6         23.7          24.9             2.3
## 5     10    Large          33.0         34.7          36.3             3.3
## 13    18    Large          18.0         18.8          19.6             1.6
## 15    20    Large          18.4         18.4          18.4             0.0
## 17    22    Large          29.5         29.5          29.5             0.0
## 25    30    Large          17.5         19.3          21.2             3.7
## 33    38    Large          20.1         20.9          21.7             1.6
## 35    52    Large          34.4         36.1          37.8             3.4
## 41    71    Large          19.5         20.7          21.9             2.4
## 47    77    Large          19.4         24.4          29.4            10.0
##    The_Rough_Range G_P_M_100 Miles_Per_Gallon_City Miles_Per_Gallon_Highway
## 2             1.79       4.2                    19                       28
## 3             2.31       4.9                    16                       25
## 5             3.30       4.9                    16                       25
## 13            1.60       4.7                    17                       26
## 15           -0.01       4.2                    20                       28
## 17            0.02       4.3                    20                       26
## 25            3.69       4.2                    20                       28
## 33            1.59       4.5                    18                       26
## 35            3.42       4.5                    18                       26
## 41            2.41       4.2                    19                       28
## 47           10.00       4.2                    19                       28

Use the summary function to create an overview of your new data frame. The print the mean and median for the same two attributes. Please compare.

summary(bigOlecars)
##      Index         Car_Type         Minimum_Price    Actual_Price  
##  Min.   : 7.00   Length:11          Min.   :17.50   Min.   :18.40  
##  1st Qu.:14.00   Class :character   1st Qu.:18.90   1st Qu.:20.00  
##  Median :22.00   Mode  :character   Median :19.90   Median :20.90  
##  Mean   :32.09                      Mean   :22.94   Mean   :24.30  
##  3rd Qu.:45.00                      3rd Qu.:26.05   3rd Qu.:26.95  
##  Max.   :77.00                      Max.   :34.40   Max.   :36.10  
##  Maximum_Price   The_Range_Price  The_Rough_Range    G_P_M_100    
##  Min.   :18.40   Min.   : 0.000   Min.   :-0.010   Min.   :4.200  
##  1st Qu.:21.45   1st Qu.: 1.600   1st Qu.: 1.595   1st Qu.:4.200  
##  Median :21.90   Median : 2.300   Median : 2.310   Median :4.300  
##  Mean   :25.67   Mean   : 2.736   Mean   : 2.738   Mean   :4.436  
##  3rd Qu.:29.45   3rd Qu.: 3.350   3rd Qu.: 3.360   3rd Qu.:4.600  
##  Max.   :37.80   Max.   :10.000   Max.   :10.000   Max.   :4.900  
##  Miles_Per_Gallon_City Miles_Per_Gallon_Highway
##  Min.   :16.00         Min.   :25.00           
##  1st Qu.:17.50         1st Qu.:26.00           
##  Median :19.00         Median :26.00           
##  Mean   :18.36         Mean   :26.73           
##  3rd Qu.:19.50         3rd Qu.:28.00           
##  Max.   :20.00         Max.   :28.00
mean(bigOlecars$Actual_Price)
## [1] 24.3
median(bigOlecars$Actual_Price)
## [1] 20.9
mean(cars$Price)
## [1] 18.57292
median(cars$Price)
## [1] 16.3
mean(bigOlecars$Miles_Per_Gallon_City)
## [1] 18.36364
median(bigOlecars$Miles_Per_Gallon_City)
## [1] 19
mean(cars$MPG.city)
## [1] 20.95833
median(cars$MPG.city)
## [1] 20

Means will change as the amount of columns and rows that are counted up and divided by change. As for medians; they change because when the amount of the numbers you are looking at change, so too the number in the middle.

For at least 3 values in a column please rename so that every value in that column is renamed. For example, suppose I have 20 values of the letter “e” in one column. Rename those values so that all 20 would show as “excellent”.

cars$Price[cars$Price == "40.1"] <- "1st"
cars$Price[cars$Price == "38.0"] <- "2nd"
cars$Price[cars$Price == "36.1"] <- "3rd"
  1. Display enough rows to see examples of all of steps 1-5 above.
head(cars)
##    X    Type Min.Price Price Max.Price Range.Price RoughRange gpm100 MPG.city
## 1  6 Midsize      14.2  15.7      17.3         3.1       3.09    3.8       22
## 2  7   Large      19.9  20.8      21.7         1.8       1.79    4.2       19
## 3  8   Large      22.6  23.7      24.9         2.3       2.31    4.9       16
## 4  9 Midsize      26.3  26.3      26.3         0.0      -0.01    4.3       19
## 5 10   Large      33.0  34.7      36.3         3.3       3.30    4.9       16
## 6 11 Midsize      37.5   1st      42.7         5.2       5.18    4.9       16
##   MPG.highway
## 1          31
## 2          28
## 3          25
## 4          27
## 5          25
## 6          25

```