RSocrata: Download 'Socrata' Data Sets as R Data Frames
SocrataのデータをRのデータフレームとして扱うためのパッケージ
- CRAN: http://cran.r-project.org/web/packages/RSocrata/index.html
- GitHub: https://github.com/Chicago/RSocrata
> library(RSocrata)
バージョン: 1.6.2.10
関数名 | 概略 |
---|---|
fieldName |
Convert Socrata human-readable column name to field name |
isFourByFour |
Checks the validity of the syntax for a potential Socrata dataset Unique Identifier, also known as a 4x4. |
ls.socrata |
List datasets available from a Socrata domain |
posixify |
Convert Socrata calendar_date string to POSIX |
read.socrata |
Get a full Socrata data set as an R data frame |
validateUrl |
Convert, if necessary, URL to valid REST API URL supported by Socrata. |
fieldName
(大文字を小文字にし、ピリオドをアンダーバーで置き換える)
> fieldName("Number.of.Stations")
[1] "number_of_stations"
> names(iris) %>% fieldName()
[1] "sepal_length" "sepal_width" "petal_length" "petal_width"
[5] "species"
ls.socrata
利用可能なデータセットの一覧
> ls.socrata("http://soda.demo.socrata.com") %>% {
+ print(nrow(.))
+ names(.)
+ }
[1] 39
[1] "accessLevel" "landingPage" "issued" "modified"
[5] "contactPoint" "identifier" "publisher" "description"
[9] "title" "distribution" "keyword" "theme"
[13] "license"
read.socrata
Socrataデータの取得
> read.socrata(url ="http://soda.demo.socrata.com/resource/4334-bgaj.csv") %>% {
+ print(class(.))
+ print(dim(.))
+ str(.)
+ }
[1] "data.frame"
[1] 1007 9
'data.frame': 1007 obs. of 9 variables:
$ Source : chr "nn" "ci" "nc" "nn" ...
$ Earthquake.ID : chr "00388610" "15215753" "71842370" "00388609" ...
$ Version : chr "9" "0" "0" "9" ...
$ Datetime : POSIXlt, format: "2012-09-14 22:38:01" "2012-09-14 22:14:45" ...
$ Magnitude : num 2.7 1.5 1.4 1.5 1.7 3.1 1.8 2.3 1.6 2.3 ...
$ Depth : num 7.6 10.6 0 8.2 6.4 20 6 30.8 2.1 27.8 ...
$ Number.of.Stations: int 15 35 21 29 29 6 17 36 29 13 ...
$ Region : chr "Nevada" "Southern California" "Northern California" "Central California" ...
$ Location : chr "(41.1085, -117.6135)" "(34.525, -118.1527)" "(38.8023, -122.7685)" "(36.9447, -117.6778)" ...