For week two’s R assignment I selected Prestige which looks at the prestige of various Canadian jobs.

Loading the Data:

df = read.csv( "https://raw.githubusercontent.com/kaiserxc/CUNY_MSDA/master/Prestige.csv")

Summary and means:

summary(df)
##                   X        education          income          women       
##  accountants       : 1   Min.   : 6.380   Min.   :  611   Min.   : 0.000  
##  aircraft.repairmen: 1   1st Qu.: 8.445   1st Qu.: 4106   1st Qu.: 3.592  
##  aircraft.workers  : 1   Median :10.540   Median : 5930   Median :13.600  
##  architects        : 1   Mean   :10.738   Mean   : 6798   Mean   :28.979  
##  athletes          : 1   3rd Qu.:12.648   3rd Qu.: 8187   3rd Qu.:52.203  
##  auto.repairmen    : 1   Max.   :15.970   Max.   :25879   Max.   :97.510  
##  (Other)           :96                                                    
##     prestige         census       type   
##  Min.   :14.80   Min.   :1113   bc  :44  
##  1st Qu.:35.23   1st Qu.:3120   prof:31  
##  Median :43.60   Median :5135   wc  :23  
##  Mean   :46.83   Mean   :5402   NA's: 4  
##  3rd Qu.:59.27   3rd Qu.:8312            
##  Max.   :87.20   Max.   :9517            
## 
df %>% 
  summarise(AverageEducation = mean(education),
            MedianEducation = median(education),
            AverageIncome = mean(income),
            MedianIncome = median(income))
##   AverageEducation MedianEducation AverageIncome MedianIncome
## 1         10.73804           10.54      6797.902       5930.5

Quick correlation matrix to see trends.

pairs(df)

# 2) Create a new data frame with a subset of the columns and rows. Make sure to rename it.

df1 = df %>% select(-type, -census)

3) Create new column names for the new data frame.

df1 = rename(df1,Occupation = X, Education = education, Income = income,
                Women = women, Prestige = prestige)

4) 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(df)
##                   X        education          income          women       
##  accountants       : 1   Min.   : 6.380   Min.   :  611   Min.   : 0.000  
##  aircraft.repairmen: 1   1st Qu.: 8.445   1st Qu.: 4106   1st Qu.: 3.592  
##  aircraft.workers  : 1   Median :10.540   Median : 5930   Median :13.600  
##  architects        : 1   Mean   :10.738   Mean   : 6798   Mean   :28.979  
##  athletes          : 1   3rd Qu.:12.648   3rd Qu.: 8187   3rd Qu.:52.203  
##  auto.repairmen    : 1   Max.   :15.970   Max.   :25879   Max.   :97.510  
##  (Other)           :96                                                    
##     prestige         census       type   
##  Min.   :14.80   Min.   :1113   bc  :44  
##  1st Qu.:35.23   1st Qu.:3120   prof:31  
##  Median :43.60   Median :5135   wc  :23  
##  Mean   :46.83   Mean   :5402   NA's: 4  
##  3rd Qu.:59.27   3rd Qu.:8312            
##  Max.   :87.20   Max.   :9517            
## 
summary(df1)
##               Occupation   Education          Income          Women       
##  accountants       : 1   Min.   : 6.380   Min.   :  611   Min.   : 0.000  
##  aircraft.repairmen: 1   1st Qu.: 8.445   1st Qu.: 4106   1st Qu.: 3.592  
##  aircraft.workers  : 1   Median :10.540   Median : 5930   Median :13.600  
##  architects        : 1   Mean   :10.738   Mean   : 6798   Mean   :28.979  
##  athletes          : 1   3rd Qu.:12.648   3rd Qu.: 8187   3rd Qu.:52.203  
##  auto.repairmen    : 1   Max.   :15.970   Max.   :25879   Max.   :97.510  
##  (Other)           :96                                                    
##     Prestige    
##  Min.   :14.80  
##  1st Qu.:35.23  
##  Median :43.60  
##  Mean   :46.83  
##  3rd Qu.:59.27  
##  Max.   :87.20  
## 
df %>% 
  summarise(AverageEducation = mean(education),
            MedianEducation = median(education),
            AverageIncome = mean(income),
            MedianIncome = median(income))
##   AverageEducation MedianEducation AverageIncome MedianIncome
## 1         10.73804           10.54      6797.902       5930.5
df1 %>% 
  summarise(AverageEducation = mean(Education),
            MedianEducation = median(Education),
            AverageIncome = mean(Income),
            MedianIncome = median(Income))
##   AverageEducation MedianEducation AverageIncome MedianIncome
## 1         10.73804           10.54      6797.902       5930.5

Turns out they are the same.

5) 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”.

(We are going to have to use the original df for this)

df3 =  mutate(df, type = ifelse(type == "prof", "Management", 
                           ifelse(type == 'wc', "WhiteCollar", "BlueCollar")))

6) Display enough rows to see examples of all of steps 1-5 above.

kable(df3)
X education income women prestige census type
gov.administrators 13.11 12351 11.16 68.8 1113 Management
general.managers 12.26 25879 4.02 69.1 1130 Management
accountants 12.77 9271 15.70 63.4 1171 Management
purchasing.officers 11.42 8865 9.11 56.8 1175 Management
chemists 14.62 8403 11.68 73.5 2111 Management
physicists 15.64 11030 5.13 77.6 2113 Management
biologists 15.09 8258 25.65 72.6 2133 Management
architects 15.44 14163 2.69 78.1 2141 Management
civil.engineers 14.52 11377 1.03 73.1 2143 Management
mining.engineers 14.64 11023 0.94 68.8 2153 Management
surveyors 12.39 5902 1.91 62.0 2161 Management
draughtsmen 12.30 7059 7.83 60.0 2163 Management
computer.programers 13.83 8425 15.33 53.8 2183 Management
economists 14.44 8049 57.31 62.2 2311 Management
psychologists 14.36 7405 48.28 74.9 2315 Management
social.workers 14.21 6336 54.77 55.1 2331 Management
lawyers 15.77 19263 5.13 82.3 2343 Management
librarians 14.15 6112 77.10 58.1 2351 Management
vocational.counsellors 15.22 9593 34.89 58.3 2391 Management
ministers 14.50 4686 4.14 72.8 2511 Management
university.teachers 15.97 12480 19.59 84.6 2711 Management
primary.school.teachers 13.62 5648 83.78 59.6 2731 Management
secondary.school.teachers 15.08 8034 46.80 66.1 2733 Management
physicians 15.96 25308 10.56 87.2 3111 Management
veterinarians 15.94 14558 4.32 66.7 3115 Management
osteopaths.chiropractors 14.71 17498 6.91 68.4 3117 Management
nurses 12.46 4614 96.12 64.7 3131 Management
nursing.aides 9.45 3485 76.14 34.9 3135 BlueCollar
physio.therapsts 13.62 5092 82.66 72.1 3137 Management
pharmacists 15.21 10432 24.71 69.3 3151 Management
medical.technicians 12.79 5180 76.04 67.5 3156 WhiteCollar
commercial.artists 11.09 6197 21.03 57.2 3314 Management
radio.tv.announcers 12.71 7562 11.15 57.6 3337 WhiteCollar
athletes 11.44 8206 8.13 54.1 3373 NA
secretaries 11.59 4036 97.51 46.0 4111 WhiteCollar
typists 11.49 3148 95.97 41.9 4113 WhiteCollar
bookkeepers 11.32 4348 68.24 49.4 4131 WhiteCollar
tellers.cashiers 10.64 2448 91.76 42.3 4133 WhiteCollar
computer.operators 11.36 4330 75.92 47.7 4143 WhiteCollar
shipping.clerks 9.17 4761 11.37 30.9 4153 WhiteCollar
file.clerks 12.09 3016 83.19 32.7 4161 WhiteCollar
receptionsts 11.04 2901 92.86 38.7 4171 WhiteCollar
mail.carriers 9.22 5511 7.62 36.1 4172 WhiteCollar
postal.clerks 10.07 3739 52.27 37.2 4173 WhiteCollar
telephone.operators 10.51 3161 96.14 38.1 4175 WhiteCollar
collectors 11.20 4741 47.06 29.4 4191 WhiteCollar
claim.adjustors 11.13 5052 56.10 51.1 4192 WhiteCollar
travel.clerks 11.43 6259 39.17 35.7 4193 WhiteCollar
office.clerks 11.00 4075 63.23 35.6 4197 WhiteCollar
sales.supervisors 9.84 7482 17.04 41.5 5130 WhiteCollar
commercial.travellers 11.13 8780 3.16 40.2 5133 WhiteCollar
sales.clerks 10.05 2594 67.82 26.5 5137 WhiteCollar
newsboys 9.62 918 7.00 14.8 5143 NA
service.station.attendant 9.93 2370 3.69 23.3 5145 BlueCollar
insurance.agents 11.60 8131 13.09 47.3 5171 WhiteCollar
real.estate.salesmen 11.09 6992 24.44 47.1 5172 WhiteCollar
buyers 11.03 7956 23.88 51.1 5191 WhiteCollar
firefighters 9.47 8895 0.00 43.5 6111 BlueCollar
policemen 10.93 8891 1.65 51.6 6112 BlueCollar
cooks 7.74 3116 52.00 29.7 6121 BlueCollar
bartenders 8.50 3930 15.51 20.2 6123 BlueCollar
funeral.directors 10.57 7869 6.01 54.9 6141 BlueCollar
babysitters 9.46 611 96.53 25.9 6147 NA
launderers 7.33 3000 69.31 20.8 6162 BlueCollar
janitors 7.11 3472 33.57 17.3 6191 BlueCollar
elevator.operators 7.58 3582 30.08 20.1 6193 BlueCollar
farmers 6.84 3643 3.60 44.1 7112 NA
farm.workers 8.60 1656 27.75 21.5 7182 BlueCollar
rotary.well.drillers 8.88 6860 0.00 35.3 7711 BlueCollar
bakers 7.54 4199 33.30 38.9 8213 BlueCollar
slaughterers.1 7.64 5134 17.26 25.2 8215 BlueCollar
slaughterers.2 7.64 5134 17.26 34.8 8215 BlueCollar
canners 7.42 1890 72.24 23.2 8221 BlueCollar
textile.weavers 6.69 4443 31.36 33.3 8267 BlueCollar
textile.labourers 6.74 3485 39.48 28.8 8278 BlueCollar
tool.die.makers 10.09 8043 1.50 42.5 8311 BlueCollar
machinists 8.81 6686 4.28 44.2 8313 BlueCollar
sheet.metal.workers 8.40 6565 2.30 35.9 8333 BlueCollar
welders 7.92 6477 5.17 41.8 8335 BlueCollar
auto.workers 8.43 5811 13.62 35.9 8513 BlueCollar
aircraft.workers 8.78 6573 5.78 43.7 8515 BlueCollar
electronic.workers 8.76 3942 74.54 50.8 8534 BlueCollar
radio.tv.repairmen 10.29 5449 2.92 37.2 8537 BlueCollar
sewing.mach.operators 6.38 2847 90.67 28.2 8563 BlueCollar
auto.repairmen 8.10 5795 0.81 38.1 8581 BlueCollar
aircraft.repairmen 10.10 7716 0.78 50.3 8582 BlueCollar
railway.sectionmen 6.67 4696 0.00 27.3 8715 BlueCollar
electrical.linemen 9.05 8316 1.34 40.9 8731 BlueCollar
electricians 9.93 7147 0.99 50.2 8733 BlueCollar
construction.foremen 8.24 8880 0.65 51.1 8780 BlueCollar
carpenters 6.92 5299 0.56 38.9 8781 BlueCollar
masons 6.60 5959 0.52 36.2 8782 BlueCollar
house.painters 7.81 4549 2.46 29.9 8785 BlueCollar
plumbers 8.33 6928 0.61 42.9 8791 BlueCollar
construction.labourers 7.52 3910 1.09 26.5 8798 BlueCollar
pilots 12.27 14032 0.58 66.1 9111 Management
train.engineers 8.49 8845 0.00 48.9 9131 BlueCollar
bus.drivers 7.58 5562 9.47 35.9 9171 BlueCollar
taxi.drivers 7.93 4224 3.59 25.1 9173 BlueCollar
longshoremen 8.37 4753 0.00 26.1 9313 BlueCollar
typesetters 10.00 6462 13.58 42.2 9511 BlueCollar
bookbinders 8.55 3617 70.87 35.2 9517 BlueCollar