23 Read and write
23.1 Comma Separated Values
The file 2011_OAC_Raw_uVariables_Leicester.csv
- contains data used for the 2011 Output Area Classificagtion
- 167 variables, as well as the resulting groups
- for the city of Leicester
Extract showing only some columns
OA11CD,LSOA11CD, ... supgrpcode,supgrpname,Total_Population, ...
E00069517,E01013785, ... 6,Suburbanites,313, ...
E00169516,E01013713, ... 4,Multicultural Metropolitans,341, ...
E00169048,E01032862, ... 4,Multicultural Metropolitans,345, ...
The full variable names can be found in the file
- 2011_OAC_Raw_uVariables_Lookup.csv
.
23.2 Read
The read_csv
function of the readr
library reads a csv file from the path provided as the first argument
leicester_2011OAC <- read_csv("2011_OAC_Raw_uVariables_Leicester.csv")
leicester_2011OAC %>%
select(OA11CD,LSOA11CD, supgrpcode,supgrpname,Total_Population) %>%
top_n(3) %>%
kable()
OA11CD | LSOA11CD | supgrpcode | supgrpname | Total_Population |
---|---|---|---|---|
E00169553 | E01013648 | 2 | Cosmopolitans | 714 |
E00069303 | E01013739 | 4 | Multicultural Metropolitans | 623 |
E00168096 | E01013689 | 2 | Cosmopolitans | 708 |
23.3 Write
The function write_csv
can be used to save a dataset to csv
Example:
- read the 2011 OAC dataset
- select a few columns
- filter only those OA in the supergroup Suburbanites (code
6
) - write the results to a file named Leicester_Suburbanites.csv in your home folder