collegeDistance <- read.csv("https://vincentarelbundock.github.io/Rdatasets/csv/AER/CollegeDistance.csv", header = TRUE)
highIncomeMale <- subset(collegeDistance,gender=="male" & income == "high")
highIncomeMale$state <-"New York"
highIncomeMale$state <-"New York"
highIncomeMale$city <-"Brooklyn"
# for all the education field values that are 16, change the state field value to New Jersey.
highIncomeMale$state[highIncomeMale$education == 16]<-"New Jersey"
# Displaying the first 100 rows to see all examples done in steps 1-5.
head(highIncomeMale,100)
## X gender ethnicity score fcollege mcollege home urban unemp wage
## 1 1 male other 39.15 yes no yes yes 6.2 8.09
## 22 22 male other 59.56 yes no yes no 7.7 7.04
## 33 33 male other 58.66 yes no yes yes 5.1 8.85
## 38 38 male other 61.03 yes no no no 6.2 8.09
## 39 39 male other 54.35 no no no no 6.2 8.09
## 41 41 male other 70.10 yes no yes no 6.2 8.09
## 61 61 male other 57.74 no no yes no 5.5 8.09
## 62 62 male other 60.38 yes no yes no 5.5 8.09
## 63 63 male other 62.77 no no no no 5.5 8.09
## 70 70 male other 53.21 no no yes no 6.9 7.04
## 74 74 male other 60.22 yes no yes no 7.7 7.04
## 77 77 male other 51.84 yes yes no no 4.4 8.09
## 80 80 male other 57.50 no yes yes no 4.4 8.09
## 82 82 male other 50.62 yes no yes no 7.5 8.09
## 97 97 male other 56.47 yes no yes no 5.3 8.09
## 105 105 male other 66.95 yes yes yes no 6.1 7.69
## 112 112 male other 44.46 yes yes yes no 5.4 8.09
## 117 117 male hispanic 38.95 no no yes no 13.5 7.69
## 122 122 male other 44.46 no no yes no 8.7 8.85
## 127 127 male other 52.74 yes no yes no 6.5 8.09
## 129 129 male other 40.18 no no yes no 6.5 8.09
## 138 138 male other 51.10 no no yes no 7.8 7.69
## 144 144 male other 56.35 no no yes no 5.4 8.85
## 147 147 male other 66.17 yes yes yes no 5.4 8.85
## 148 148 male other 45.10 no no yes no 5.4 8.85
## 151 151 male other 52.98 yes yes yes no 7.2 8.85
## 155 155 male other 58.62 no no yes no 4.4 8.09
## 158 158 male other 64.83 yes yes yes no 4.4 8.09
## 161 161 male other 66.49 no no yes no 4.4 8.09
## 162 162 male other 62.14 yes yes yes no 4.4 8.09
## 171 171 male other 52.64 no yes yes no 5.1 8.85
## 179 179 male other 62.98 yes no yes no 10.4 7.69
## 190 190 male other 63.13 no yes yes yes 5.1 8.85
## 192 192 male other 59.91 no yes yes yes 5.1 8.85
## 195 195 male other 57.49 no no yes no 6.3 9.64
## 201 201 male afam 44.24 no no no yes 8.0 9.64
## 202 202 male afam 51.33 yes yes yes yes 8.0 9.64
## 203 203 male afam 56.46 no yes no yes 8.0 9.64
## 210 210 male other 62.36 yes yes no yes 8.0 9.64
## 228 228 male other 43.22 no no yes no 9.5 9.64
## 232 232 male afam 37.61 no yes yes no 5.3 9.64
## 248 248 male other 62.20 yes no yes no 9.8 9.64
## 258 258 male other 60.96 no no yes no 10.7 9.64
## 262 262 male other 63.12 yes yes yes no 10.7 9.64
## 269 269 male other 56.30 yes yes yes no 5.3 9.64
## 283 283 male other 58.92 no no yes no 8.0 9.64
## 286 286 male other 56.02 no no yes no 8.0 9.64
## 287 287 male other 58.58 yes yes yes no 5.3 9.64
## 296 296 male other 58.25 yes no no no 4.4 9.64
## 297 297 male other 61.87 yes yes yes no 4.4 9.64
## 298 298 male other 67.62 yes yes yes no 4.4 9.64
## 300 300 male afam 58.41 yes yes yes no 4.4 9.64
## 301 301 male other 66.83 yes no yes no 4.4 9.64
## 303 303 male afam 52.78 no no no no 4.4 9.64
## 307 307 male other 53.03 yes no yes no 8.7 9.64
## 315 315 male other 61.26 yes yes yes no 8.7 9.64
## 324 324 male afam 48.39 no no yes no 5.6 9.64
## 328 328 male other 62.44 yes yes yes yes 8.0 9.64
## 342 342 male other 54.24 no no no yes 9.5 9.64
## 348 348 male other 58.78 yes yes yes no 12.6 9.64
## 349 349 male other 62.49 yes no yes no 8.0 9.64
## 353 353 male other 60.81 no no yes no 8.0 9.64
## 359 359 male other 54.87 yes no yes no 10.8 9.64
## 360 360 male other 49.11 no no yes no 10.8 9.64
## 365 365 male other 58.06 no no yes no 9.5 9.64
## 370 370 male other 59.96 yes no yes no 9.5 9.64
## 371 371 male other 60.44 no no yes no 5.3 9.64
## 372 372 male other 44.47 yes yes yes no 5.3 9.64
## 374 374 male other 59.56 yes yes yes no 5.3 9.64
## 375 375 male other 64.89 yes no yes no 5.3 9.64
## 376 376 male other 58.24 no no yes no 5.3 9.64
## 378 378 male other 62.20 yes no yes no 5.3 9.64
## 381 381 male other 60.95 yes no yes no 5.3 9.64
## 384 384 male other 59.34 no no yes no 6.3 9.64
## 393 393 male other 42.84 no no yes yes 8.0 9.64
## 399 399 male other 65.67 yes yes yes no 5.3 9.64
## 400 400 male other 61.87 yes yes no no 4.4 9.64
## 401 401 male other 61.28 yes yes yes no 4.4 9.64
## 402 402 male other 62.18 no yes yes no 4.4 9.64
## 403 403 male afam 60.18 yes yes yes no 4.4 9.64
## 407 407 male other 49.32 yes no yes no 5.1 9.64
## 408 408 male other 53.33 no no yes no 5.1 9.64
## 409 409 male afam 48.70 no yes yes no 5.1 9.64
## 423 423 male other 51.88 no no yes no 7.6 9.64
## 429 429 male other 54.76 no yes yes no 6.7 10.04
## 432 432 male other 62.03 yes yes yes no 5.6 10.04
## 435 435 male other 56.17 yes yes no no 5.6 10.04
## 438 438 male other 56.72 no no no no 4.8 10.04
## 442 442 male other 62.52 no no yes no 6.2 10.04
## 445 445 male hispanic 41.54 no no yes no 7.4 10.04
## 451 451 male afam 54.94 no no no no 7.7 10.04
## 452 452 male afam 41.19 yes yes yes no 7.7 10.04
## 457 457 male other 60.95 yes yes yes no 7.7 10.04
## 459 459 male other 69.30 yes no yes no 7.7 10.04
## 464 464 male other 60.67 no yes yes no 6.7 10.04
## 471 471 male other 65.05 yes yes yes no 5.9 10.04
## 473 473 male other 58.02 yes no yes no 5.9 10.04
## 483 483 male other 61.44 yes no yes no 4.8 10.04
## 487 487 male other 57.20 no no yes no 4.8 10.04
## 497 497 male afam 47.46 no no no no 6.2 10.04
## distance tuition education income region state city
## 1 0.2 0.88915 12 high other New York Brooklyn
## 22 0.5 0.90300 14 high other New York Brooklyn
## 33 0.5 0.84988 16 high other New Jersey Brooklyn
## 38 0.6 0.88915 14 high other New York Brooklyn
## 39 0.6 0.88915 15 high other New York Brooklyn
## 41 0.6 0.88915 17 high other New York Brooklyn
## 61 1.5 0.88915 16 high other New Jersey Brooklyn
## 62 1.5 0.88915 12 high other New York Brooklyn
## 63 1.5 0.88915 12 high other New York Brooklyn
## 70 2.0 0.90300 18 high other New York Brooklyn
## 74 2.0 0.90300 12 high other New York Brooklyn
## 77 0.5 0.88915 18 high other New York Brooklyn
## 80 0.5 0.88915 12 high other New York Brooklyn
## 82 0.5 0.88915 14 high other New York Brooklyn
## 97 0.1 0.88915 13 high other New York Brooklyn
## 105 2.5 1.11201 16 high other New Jersey Brooklyn
## 112 1.9 0.88915 12 high other New York Brooklyn
## 117 5.0 1.11201 13 high other New York Brooklyn
## 122 1.5 0.84988 12 high other New York Brooklyn
## 127 0.8 0.88915 12 high other New York Brooklyn
## 129 0.8 0.88915 12 high other New York Brooklyn
## 138 1.8 1.11201 13 high other New York Brooklyn
## 144 0.8 0.84988 15 high other New York Brooklyn
## 147 0.8 0.84988 16 high other New Jersey Brooklyn
## 148 0.8 0.84988 13 high other New York Brooklyn
## 151 0.8 0.84988 13 high other New York Brooklyn
## 155 1.5 0.88915 13 high other New York Brooklyn
## 158 1.5 0.88915 15 high other New York Brooklyn
## 161 1.5 0.88915 17 high other New York Brooklyn
## 162 1.5 0.88915 17 high other New York Brooklyn
## 171 0.1 0.84988 15 high other New York Brooklyn
## 179 0.0 1.11201 18 high other New York Brooklyn
## 190 1.5 0.84988 17 high other New York Brooklyn
## 192 1.5 0.84988 15 high other New York Brooklyn
## 195 2.0 1.15242 17 high other New York Brooklyn
## 201 0.0 1.15242 14 high other New York Brooklyn
## 202 0.0 1.15242 13 high other New York Brooklyn
## 203 0.4 1.15242 15 high other New York Brooklyn
## 210 1.5 1.15242 16 high other New Jersey Brooklyn
## 228 0.8 1.15242 12 high other New York Brooklyn
## 232 0.3 1.15242 13 high other New York Brooklyn
## 248 4.5 1.15242 16 high other New Jersey Brooklyn
## 258 0.5 1.15242 17 high other New York Brooklyn
## 262 0.5 1.15242 16 high other New Jersey Brooklyn
## 269 1.2 1.15242 12 high other New York Brooklyn
## 283 3.5 1.15242 17 high other New York Brooklyn
## 286 3.5 1.15242 16 high other New Jersey Brooklyn
## 287 0.7 1.15242 16 high other New Jersey Brooklyn
## 296 0.3 1.15242 15 high other New York Brooklyn
## 297 0.3 1.15242 16 high other New Jersey Brooklyn
## 298 0.3 1.15242 13 high other New York Brooklyn
## 300 0.3 1.15242 15 high other New York Brooklyn
## 301 0.3 1.15242 16 high other New Jersey Brooklyn
## 303 0.3 1.15242 16 high other New Jersey Brooklyn
## 307 2.0 1.15242 16 high other New Jersey Brooklyn
## 315 2.0 1.15242 16 high other New Jersey Brooklyn
## 324 0.5 1.15242 16 high other New Jersey Brooklyn
## 328 0.7 1.15242 16 high other New Jersey Brooklyn
## 342 0.3 1.15242 16 high other New Jersey Brooklyn
## 348 5.2 1.15242 16 high other New Jersey Brooklyn
## 349 6.0 1.15242 16 high other New Jersey Brooklyn
## 353 6.0 1.15242 16 high other New Jersey Brooklyn
## 359 6.5 1.15242 16 high other New Jersey Brooklyn
## 360 6.5 1.15242 12 high other New York Brooklyn
## 365 2.0 1.15242 15 high other New York Brooklyn
## 370 2.0 1.15242 14 high other New York Brooklyn
## 371 0.5 1.15242 12 high other New York Brooklyn
## 372 0.5 1.15242 15 high other New York Brooklyn
## 374 0.5 1.15242 16 high other New Jersey Brooklyn
## 375 0.5 1.15242 13 high other New York Brooklyn
## 376 0.5 1.15242 15 high other New York Brooklyn
## 378 0.5 1.15242 15 high other New York Brooklyn
## 381 0.5 1.15242 15 high other New York Brooklyn
## 384 0.4 1.15242 12 high other New York Brooklyn
## 393 1.0 1.15242 12 high other New York Brooklyn
## 399 1.1 1.15242 15 high other New York Brooklyn
## 400 0.1 1.15242 16 high other New Jersey Brooklyn
## 401 0.1 1.15242 17 high other New York Brooklyn
## 402 0.1 1.15242 17 high other New York Brooklyn
## 403 0.1 1.15242 16 high other New Jersey Brooklyn
## 407 0.5 1.15242 17 high other New York Brooklyn
## 408 0.5 1.15242 17 high other New York Brooklyn
## 409 0.5 1.15242 13 high other New York Brooklyn
## 423 0.1 1.15242 12 high other New York Brooklyn
## 429 1.5 1.12702 16 high other New Jersey Brooklyn
## 432 0.5 1.12702 15 high other New York Brooklyn
## 435 0.5 1.12702 13 high other New York Brooklyn
## 438 1.0 1.12702 14 high other New York Brooklyn
## 442 1.5 1.12702 15 high other New York Brooklyn
## 445 4.5 1.12702 12 high other New York Brooklyn
## 451 0.7 1.12702 16 high other New Jersey Brooklyn
## 452 0.7 1.12702 16 high other New Jersey Brooklyn
## 457 0.5 1.12702 17 high other New York Brooklyn
## 459 0.5 1.12702 18 high other New York Brooklyn
## 464 1.2 1.12702 13 high other New York Brooklyn
## 471 1.5 1.12702 16 high other New Jersey Brooklyn
## 473 1.5 1.12702 13 high other New York Brooklyn
## 483 1.5 1.12702 18 high other New York Brooklyn
## 487 1.5 1.12702 16 high other New Jersey Brooklyn
## 497 0.5 1.12702 13 high other New York Brooklyn