[1] "this is the output from the code chunk"
URBAN DATA ANALYSIS, MAPPING AND VISUALIZATION Section A | Fall 2022
Sara Hodges (she/her/hers) | hodgess@newschool.edu
Slack workspace: duemethods1fall2022.slack.com
Class: Mondays, 9am - 11:40am
Building: Parsons 2 W 13th St
Room: 1108
Lecture and/or Reading Discussion
Homework Assignments Questions
Lab
Canvas and Slack
Each week:
Ongoing:
Quantitative Research Project using R, on the topic of your choosing
From R for Data Science Hadley Wickham & Garrett Grolemund
R is free, and open source
CRAN: software repository for R + gatekeepers for new packages
RStudio: the company that created RStudio application
Install R
Install RStudio
I use Quarto to make slides and an e-book for this course.
It contains text and executable R code together
Text in a box is a code chunk - something you can execute in R
The output from the code chunk displays below the box
[1] "this is the output from the code chunk"
The Console is where you can type code that executes immediately, and where you view the output.
Type into your console, and then press enter:
Notice
Create new objects (variables):
variable_name <- value of the variable
<- is the ‘assignment operator’, it is like an equal sign
Notice
<-
# tells R not to run that line of code
Notice
Use the Source Pane to write scripts to save your work.
Or to open and run existing scripts.
#)Notice
Projects are a good way to keep track of all of the files for a specific task or project. We’ll create projects for each class in this course.
In-class exercise: Create a project
Create ProjectNotice
There are lots of useful tabs in this pane
The Files window is like file explorer
Notice
You should be in your class1 folder to see your script
The Plots window display charts and maps you create
The Packages window lists the packages you have installed and provides a user interface to search for other packages and install them.
Packages are collections of functions and datasets developed by the R community to expand the things you can do in R.
tidyverse, have become the backbone of analysis in R.install.packages('tidyverse')The Help window is where you learn about packages and functions.
Two ways to open documentation:
??readr
The Environment shows all of the objects that you have in your workspace
If you are following along, you should have at least 4 objects in your Environment.
Now we’ll import our first dataset into R using the read_csv function:
Notice
Data tables are called dataframes in R.
Let’s explore our first data frame by typing some functions in our script
[1] "NCESID" "state_id" "State"
[4] "STATE_FIPS" "NAME" "County"
[7] "CONUM" "ENROLL" "LRPP"
[10] "SRPP" "SLRPP" "LR"
[13] "SR" "SLR" "SRPP_cola"
[16] "LRPP_cola" "SLRPP_cola" "dType"
[19] "dUrbanicity" "dOperational_schools" "dEnroll_district"
[22] "dLEP" "dWhite" "dBlack"
[25] "dHispanic" "dAsian_PI" "dHawaiian_PI"
[28] "dAmIndian_Aknative" "d2plus_races" "pctNonwhite"
[31] "TPop" "StPop" "StPov"
[34] "StPovRate" "MHI" "MPV"
[37] "sd_area" "student_per_sq_mile" "sdType"
[40] "dIEP"
Rows: 13,291
Columns: 40
$ NCESID <chr> "0100240", "0100270", "0100300", "0101410", "0100…
$ state_id <chr> "AL-001", "AL-002", "AL-003", "AL-133", "AL-004",…
$ State <chr> "Alabama", "Alabama", "Alabama", "Alabama", "Alab…
$ STATE_FIPS <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1…
$ NAME <chr> "Autauga County School District", "Baldwin County…
$ County <chr> "Autauga County", "Baldwin County", "Barbour Coun…
$ CONUM <chr> "01001", "01003", "01005", "01005", "01007", "010…
$ ENROLL <dbl> 9094, 32267, 755, 5427, 3236, 7651, 1503, 1438, 3…
$ LRPP <dbl> 2268.749, 6040.382, 2903.311, 1389.165, 2054.079,…
$ SRPP <dbl> 6269.958, 5160.443, 7099.338, 5306.799, 7152.658,…
$ SLRPP <dbl> 8538.707, 11200.824, 10002.649, 6695.965, 9206.73…
$ LR <dbl> 20632000, 194905000, 2192000, 7539000, 6647000, 1…
$ SR <dbl> 57019000, 166512000, 5360000, 28800000, 23146000,…
$ SLR <dbl> 77651000, 361417000, 7552000, 36339000, 29793000,…
$ SRPP_cola <dbl> 6593.016, 5420.633, 7932.221, 5929.385, 7956.238,…
$ LRPP_cola <dbl> 2385.645, 6344.939, 3243.923, 1552.140, 2284.849,…
$ SLRPP_cola <dbl> 8978.661, 11765.572, 11176.144, 7481.525, 10241.0…
$ dType <chr> "1-Regular local school district that is NOT a co…
$ dUrbanicity <chr> "41-Rural: Fringe", "41-Rural: Fringe", "43-Rural…
$ dOperational_schools <dbl> 15, 45, 3, 6, 9, 17, 3, 4, 7, 7, 19, 2, 3, 7, 11,…
$ dEnroll_district <dbl> 9094, 32267, 755, 5427, 3236, 7651, 1503, 1438, 3…
$ dLEP <dbl> 159, 1309, 49, 122, 51, 396, 97, 146, 8, 28, 167,…
$ dWhite <dbl> 5952, 22769, 47, 2735, 2349, 6300, 989, 31, 1030,…
$ dBlack <dbl> 2358, 3716, 592, 2232, 706, 101, 78, 1187, 1896, …
$ dHispanic <dbl> 336, 3069, 108, 350, 121, 1181, 349, 216, 42, 92,…
$ dAsian_PI <dbl> 204, 284, 3, 54, 10, 15, 17, 2, 15, 5, 54, 27, 7,…
$ dHawaiian_PI <dbl> 7, 21, 1, 14, 1, 6, 2, NA, 2, 2, 20, 3, 1, 4, 1, …
$ dAmIndian_Aknative <dbl> 30, 89, 2, 29, 9, 12, 5, 2, 2, NA, 25, 1, 4, 4, 7…
$ d2plus_races <dbl> 207, 2319, 2, 13, 40, 36, 63, NA, 28, 18, NA, 3, …
$ pctNonwhite <dbl> 0.34550253, 0.29435646, 0.93774834, 0.49603833, 0…
$ TPop <dbl> 55869, 223234, 12909, 11777, 22394, 51188, 6638, …
$ StPop <dbl> 9688, 35515, 1622, 2151, 3311, 8816, 1001, 1541, …
$ StPov <dbl> 1376, 4641, 671, 797, 808, 1843, 224, 591, 1024, …
$ StPovRate <dbl> 0.1420314, 0.1306772, 0.4136868, 0.3705253, 0.244…
$ MHI <dbl> 58731, 58320, 32243, 33132, 47542, 50198, 39669, …
$ MPV <dbl> 154500, 197900, 65500, 128100, 92800, 125100, 156…
$ sd_area <dbl> 604.4, 1609.9, 831.0, 73.5, 626.2, 634.8, 15.8, 6…
$ student_per_sq_mile <dbl> 15.046, 20.043, 0.909, 73.837, 5.168, 12.053, 95.…
$ sdType <chr> "uni", "uni", "uni", "uni", "uni", "uni", "uni", …
$ dIEP <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, N…
View the dataframe by clicking on it in the Environment pane or typing View(ed18) in the Console.
| NCESID | state_id | State | STATE_FIPS | NAME | County | CONUM | ENROLL | LRPP | SRPP | SLRPP | LR | SR | SLR | SRPP_cola | LRPP_cola | SLRPP_cola | dType | dUrbanicity | dOperational_schools | dEnroll_district | dLEP | dWhite | dBlack | dHispanic | dAsian_PI | dHawaiian_PI | dAmIndian_Aknative | d2plus_races | pctNonwhite | TPop | StPop | StPov | StPovRate | MHI | MPV | sd_area | student_per_sq_mile | sdType | dIEP |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0100240 | AL-001 | Alabama | 1 | Autauga County School District | Autauga County | 01001 | 9094 | 2268.749 | 6269.958 | 8538.707 | 20632000 | 57019000 | 77651000 | 6593.016 | 2385.645 | 8978.661 | 1-Regular local school district that is NOT a component of a supervisory union | 41-Rural: Fringe | 15 | 9094 | 159 | 5952 | 2358 | 336 | 204 | 7 | 30 | 207 | 0.3455025 | 55869 | 9688 | 1376 | 0.1420314 | 58731 | 154500 | 604.4 | 15.046 | uni | NA |
| 0100270 | AL-002 | Alabama | 1 | Baldwin County School District | Baldwin County | 01003 | 32267 | 6040.382 | 5160.443 | 11200.824 | 194905000 | 166512000 | 361417000 | 5420.633 | 6344.939 | 11765.572 | 1-Regular local school district that is NOT a component of a supervisory union | 41-Rural: Fringe | 45 | 32267 | 1309 | 22769 | 3716 | 3069 | 284 | 21 | 89 | 2319 | 0.2943565 | 223234 | 35515 | 4641 | 0.1306772 | 58320 | 197900 | 1609.9 | 20.043 | uni | NA |
Notice
Notice
| NCESID | state_id | State | STATE_FIPS | NAME | County | CONUM | ENROLL | LRPP | SRPP | SLRPP | LR | SR | SLR | SRPP_cola | LRPP_cola | SLRPP_cola | dType | dUrbanicity | dOperational_schools | dEnroll_district | dLEP | dWhite | dBlack | dHispanic | dAsian_PI | dHawaiian_PI | dAmIndian_Aknative | d2plus_races | pctNonwhite | TPop | StPop | StPov | StPovRate | MHI | MPV | sd_area | student_per_sq_mile | sdType | dIEP | county_num | percent_lep |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0100240 | AL-001 | Alabama | 1 | Autauga County School District | Autauga County | 01001 | 9094 | 2268.749 | 6269.958 | 8538.707 | 20632000 | 57019000 | 77651000 | 6593.016 | 2385.645 | 8978.661 | 1-Regular local school district that is NOT a component of a supervisory union | 41-Rural: Fringe | 15 | 9094 | 159 | 5952 | 2358 | 336 | 204 | 7 | 30 | 207 | 0.3455025 | 55869 | 9688 | 1376 | 0.1420314 | 58731 | 154500 | 604.4 | 15.046 | uni | NA | 1001 | 0.0174841 |
| 0100270 | AL-002 | Alabama | 1 | Baldwin County School District | Baldwin County | 01003 | 32267 | 6040.382 | 5160.443 | 11200.824 | 194905000 | 166512000 | 361417000 | 5420.633 | 6344.939 | 11765.572 | 1-Regular local school district that is NOT a component of a supervisory union | 41-Rural: Fringe | 45 | 32267 | 1309 | 22769 | 3716 | 3069 | 284 | 21 | 89 | 2319 | 0.2943565 | 223234 | 35515 | 4641 | 0.1306772 | 58320 | 197900 | 1609.9 | 20.043 | uni | NA | 1003 | 0.0405678 |
Notice
### Create a new dataframe for your New York
newyork18 <- subset(ed18, State == "New York")
# Calculate how many districts are there in New York?
ny_districts <- nrow(newyork18)
ny_districts[1] 682
Notice
See assignments for week 1 in Canvas.