path2 <- "C:\\data\\Ricci.csv"
FFScore <- read.table(file = path2, header = TRUE, sep = ",")
head(FFScore)
## X Race Position Oral Written Combine
## 1 1 W Captain 89.52 95 92.808
## 2 2 W Captain 80.00 95 89.000
## 3 3 W Captain 82.38 87 85.152
## 4 4 W Captain 88.57 76 81.028
## 5 5 W Captain 76.19 84 80.876
## 6 6 H Captain 76.19 82 79.676
Use the summary function to gain an overview of the data set. Then display the mean and median for at least two attributes
summary(FFScore)
## X Race Position Oral Written
## Min. : 1.00 B:27 Captain :41 Min. :40.83 Min. :46.00
## 1st Qu.: 30.25 H:23 Lieutenant:77 1st Qu.:55.39 1st Qu.:65.00
## Median : 59.50 W:68 Median :66.04 Median :71.50
## Mean : 59.50 Mean :65.52 Mean :71.65
## 3rd Qu.: 88.75 3rd Qu.:73.81 3rd Qu.:78.50
## Max. :118.00 Max. :92.08 Max. :95.00
## Combine
## Min. :45.93
## 1st Qu.:60.94
## Median :69.50
## Mean :69.20
## 3rd Qu.:75.83
## Max. :92.81
#Mean
apply(FFScore[ ,4:6], 2, mean)
## Oral Written Combine
## 65.52339 71.65254 69.20088
#Median
apply(FFScore[ ,4:6], 2, median)
## Oral Written Combine
## 66.040 71.500 69.502
Create a new data frame with a subset of the columns and rows. Make sure to rename it.
newFFScore <- FFScore[1:70,2:6]
head(newFFScore)
## Race Position Oral Written Combine
## 1 W Captain 89.52 95 92.808
## 2 W Captain 80.00 95 89.000
## 3 W Captain 82.38 87 85.152
## 4 W Captain 88.57 76 81.028
## 5 W Captain 76.19 84 80.876
## 6 H Captain 76.19 82 79.676
Create new column names for the new data frame
colnames(newFFScore) <- c("Race", "Class", "Speaking", "Writing", "Both")
head(newFFScore)
## Race Class Speaking Writing Both
## 1 W Captain 89.52 95 92.808
## 2 W Captain 80.00 95 89.000
## 3 W Captain 82.38 87 85.152
## 4 W Captain 88.57 76 81.028
## 5 W Captain 76.19 84 80.876
## 6 H Captain 76.19 82 79.676
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(newFFScore)
## Race Class Speaking Writing Both
## B:14 Captain :41 Min. :42.86 Min. :49.00 Min. :51.30
## H:10 Lieutenant:29 1st Qu.:63.44 1st Qu.:69.25 1st Qu.:69.86
## W:46 Median :71.97 Median :75.00 Median :74.47
## Mean :71.17 Mean :75.59 Mean :73.82
## 3rd Qu.:78.93 3rd Qu.:83.75 3rd Qu.:79.17
## Max. :92.08 Max. :95.00 Max. :92.81
#Mean
apply(newFFScore[,3:5], 2, mean)
## Speaking Writing Both
## 71.17400 75.58571 73.82103
#Median
apply(newFFScore[,3:5], 2, median)
## Speaking Writing Both
## 71.965 75.000 74.466
#Mean Compare
mapply(identical, apply(newFFScore[,3:5], 2, mean) ,apply(FFScore[,4:6], 2, mean))
## Speaking Writing Both
## FALSE FALSE FALSE
#Median Compare
mapply(identical, apply(newFFScore[,3:5], 2, median) ,apply(FFScore[,4:6], 2, median))
## Speaking Writing Both
## FALSE FALSE FALSE
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”.
require(stringr)
## Loading required package: stringr
race <- c(as.character(newFFScore[,1]))
race <- str_replace(race, "W", "Dawrf")
race <- str_replace(race, "B", "Night Elf")
race <- str_replace(race, "H", "Orc")
newFFScore[,1] <- race
Display enough rows to see examples of all of steps 1-5 above
head(newFFScore,30)
## Race Class Speaking Writing Both
## 1 Dawrf Captain 89.52 95 92.808
## 2 Dawrf Captain 80.00 95 89.000
## 3 Dawrf Captain 82.38 87 85.152
## 4 Dawrf Captain 88.57 76 81.028
## 5 Dawrf Captain 76.19 84 80.876
## 6 Orc Captain 76.19 82 79.676
## 7 Dawrf Captain 76.19 82 79.676
## 8 Orc Captain 70.00 84 78.400
## 9 Dawrf Captain 73.81 81 78.124
## 10 Dawrf Captain 84.29 72 76.916
## 11 Dawrf Captain 87.62 69 76.448
## 12 Dawrf Captain 80.00 74 76.400
## 13 Orc Captain 79.05 74 76.020
## 14 Dawrf Captain 73.81 77 75.724
## 15 Dawrf Captain 76.67 74 75.068
## 16 Night Elf Captain 82.38 70 74.952
## 17 Dawrf Captain 73.33 74 73.732
## 18 Dawrf Captain 70.00 76 73.600
## 19 Night Elf Captain 68.57 74 71.828
## 20 Dawrf Captain 82.38 64 71.352
## 21 Dawrf Captain 56.67 81 71.268
## 22 Night Elf Captain 70.95 70 70.380
## 23 Dawrf Captain 62.38 75 69.952
## 24 Dawrf Captain 78.57 64 69.828
## 25 Dawrf Captain 71.43 68 69.372
## 26 Dawrf Captain 71.43 68 69.372
## 27 Dawrf Captain 59.05 76 69.220
## 28 Orc Captain 60.48 75 69.192
## 29 Dawrf Captain 57.14 75 67.856
## 30 Night Elf Captain 52.38 77 67.152