How to connect to Statistics Canada JSON from R -


i'm trying connect online database through r, can found here: http://open.canada.ca/data/en/dataset/2270e3a4-447c-45f6-8e63-aea9fe94948f

how able load data table r , able change table name in code access other tables? i'm not particularly concerned language need use (json, json-ld, xml).

thanks in advance!

assuming know urls each of datasets similar question can found here:

download file https using download.file()

for becomes:

library(rcurl)  url <-  "http://www.statcan.gc.ca/cgi-bin/sum-som/fl/cstsaveascsv.cgi?filename=labr71a-eng.htm&lan=eng" x <- geturl(url) urlout <- read.csv(textconnection(x),row.names=null) 

i obtained url right-clicking access button , copying address.

i had declare row.names=null number of columns in first row not equal number of columns elsewhere, read.csv assumes row names as described here. i'm not sure if url these datasets change when updated, isn't convenient way data. json doesn't seem better intuitively being able change datasets.

at least way create list of urls , perform following:

url <- list(geturl("http://www.statcan.gc.ca/cgi-bin/sum-som/fl/cstsaveascsv.cgi?filename=labr71a-eng.htm&lan=eng"),             geturl("http://www.statcan.gc.ca/cgi-bin/sum-som/fl/cstsaveascsv.cgi?filename=labr72-eng.htm&lan=eng"))  urlout <- lapply(url,function(x) read.csv(textconnection(x),row.names=null,skip=2)) 

again don't having declare row.names=null , when @ file i'm not seeing discrepant number of columns, @ least file r environment you. may take more work perform operation on multiple urls.

in further effort obtain useful colnames:

url <-  "http://www.statcan.gc.ca/cgi-bin/sum-som/fl/cstsaveascsv.cgi?filename=labr71a-eng.htm&lan=eng" x <- geturl(url) urlout <- read.csv(textconnection(x),row.names=null, skip=2) 

the arguement skip = 2 skip first 2 rows when reading in csv, , yield header names. because headers numbers x placed in front. row 2 in case have value "number" in second column. unfortunately appears data intended use within excel, sad.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -