popdata: Ontario 2006 population by census subdivision

Description Usage Format Details Examples

Description

Data set contains the information of population, by age, sex, and census subdivision.

Usage

1

Format

A SpatialPolygonsDataFrame object, which needs the sp package for full functionality.

Details

This data is from the 2006 Census of canada offering by Statistics Canada web site, www12.statcan.gc.ca/english/census06/data/highlights/agesex/Index_PR.cfm?Lang=E&Geo=CSD&Table=1

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
data(popdata)
head(popdata@data)
## Not run: 
library(sp)
spplot(popdata, zcol='F.50_54', breaks=9, col=rainbow(8))

## End(Not run)
## Not run: 

library('raster')
library('sp')
bfile = tempfile(fileext='.zip')
download.file(
paste('http://www12.statcan.gc.ca/census-recensement/',
'2011/geo/bound-limit/files-fichiers/gcsd000a06a_e.zip',
sep=''),
bfile)
unzip(bfile, exdir=tempdir())
sfile = grep('shp$',unzip(bfile, list=TRUE)$Name, value=TRUE)
popdata = shapefile(file.path(tempdir(),sfile))
popdata$PRNAME = iconv(popdata$PRNAME, 'UTF-8', 'latin1')
popdata = popdata[grep("^Ont", popdata$PRNAME),]
popdataS= rgeos::gSimplify(popdata, 0.01, topologyPreserve=TRUE)
popdata = SpatialPolygonsDataFrame(popdataS, popdata@data)
projection(popdata) = CRS('+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0')

pfile = tempfile(fileext='zip')

download.file(
paste('https://www12.statcan.gc.ca/census-recensement/',
'2011/dp-pd/prof/details/download-telecharger/comprehensive/',
'comp_download.cfm?CTLG=92-591-XE&FMT=CSV301&Lang=E&Tab=1&',
'Geo1=PR&Code1=01&Geo2=PR&Code2=01&Data=Count&SearchText=&',
'SearchType=Begins&SearchPR=01&B1=All&Custom=&TABID=1', sep=''),
pfile, method='curl')
unzip(pfile, exdir=tempdir())
ofile = grep('ONT', unzip(pfile, list=TRUE)$Name,value=TRUE)
opop = read.table(file.path(tempdir(),ofile),header=F,skip=3, 
sep=',', nrows=163210,stringsAsFactors=FALSE)
opop= opop[grep("^([[:digit:]]|to| )+ years( and over)?$", opop[,7]),]
opop = opop[,c(1,4,7,11,13)]
colnames(opop) = c('id','name','var','M','F')
opop[,'var'] = gsub(" to ", "_", opop[,'var'])
opop[,'var'] = gsub(" years( and over)?", "", opop[,'var'])
opop[,'var'] = gsub("[[:space:]]", "", opop[,'var'])
opop2 = reshape(opop, direction='wide', 
idvar=c('id','name'),
timevar='var', v.names=c('M','F'))


popdata = sp::merge(popdata, opop2, by.x='CSDUID', by.y='id')
popdata=popdata[,c('CSDUID', grep("^(M|F)", names(popdata), value=TRUE))]



save(popdata, file=
'/home/patrick/workspace/diseasemapping/pkg/diseasemapping/data/popdata.RData',
compress='xz')

## End(Not run)

diseasemapping documentation built on Sept. 10, 2021, 9:06 a.m.