如何从 Github 中导入 csv 文件数据到 R?


如果您在 Github 上有一个 csv 文件,那么您可以直接通过使用它的 URL 导入到 R 中,但确保在存储数据的 Github 页面中单击“原始”选项。很多人不单击“原始”选项,因此他们读取 HTML 而不是 CSV,然后感到困惑。在这里,我分享了一个包含数据集列表的公共数据集。此数据集有 12 个变量。现在让我们导入它 −

> Data<-read.csv("https://raw.githubusercontent.com/curran/data/gh-pages/dataSoup/datasets.csv")

> str(Data)
'data.frame': 57 obs. of 12 variables:
$ Dataset.Name : Factor w/ 57 levels " ","2008 Election Results",..: 2 33 32 36 52 49 50 23 25 41 ...
$ Person.Adding : Factor w/ 11 levels "Curran","EJ",..: 2 2 2 6 6 6 6 6 6 6 ...
$ Date.Added : Factor w/ 14 levels "1/1/2013","11/7/2012",..: 2 2 2 2 2 2 2 2 2 2 ...
$ Dataset.Link : Factor w/ 57 levels "ask Jan...","http://api.occupy-data.org/v1/",..: 35 38 2 8 15 42 40 39 22 28 ...
$ Most.Recent.Year.in.Data: Factor w/ 9 levels "","2007","2008",..: 3 6 5 6 6 4 2 5 6 5 ...
$ Earliest.Year.In.Data : int NA NA 2003 1789 1996 1946 1960 1989 2000 2000 ...
$ Status : Factor w/ 6 levels "","much talked about",..: 5 5 5 5 5 5 5 5 5 5 ...
$ Dataset.Type : Factor w/ 8 levels "","API","Dataset",..: 3 3 2 3 3 3 3 1 1 5 ...
$ Documentation : Factor w/ 18 levels "","http://data.gov/metric",..: 1 1 17 1 6 3 1 1 1 1 ...
$ Existing.Work : Factor w/ 10 levels "","http://databits.io/challenges/airbnb-user-pathways-challenge",..: 1 1 7 1 1 1 1 1 1 1 ...
$ Tags : Factor w/ 12 levels "","astronomy",..: 11 7 8 9 1 1 1 1 1 2 ...
$ Active : Factor w/ 3 levels "","n","y": 2 2 3 3 2 3 2 2 2 2 ...
> head(Data)
Dataset.Name Person.Adding Date.Added
1 2008 Election Results EJ 11/7/2012
2 Occupy Oakland Finances EJ 11/7/2012
3 NYPD Stop-and-Frisk DB API EJ 11/7/2012
4 Presidential Speech Archive Kai 11/7/2012
5 USDA National Nutrient Database Kai 11/7/2012
6 US Foreign Aid Kai 11/7/2012
Dataset.Link
1 https://docs.google.com/spreadsheet/ccc?key=0ApAkxBfw1JT4dFliRjhYOW5WLXk1WkZfNFFQTGxmSGc#gid=0
2 https://docs.google.com/spreadsheet/pub?key=0ApAkxBfw1JT4dHhNSkpva0RrQUFfcDIyUHl3LWFCVEE&output=html
3 http://api.occupy-data.org/v1/
4 http://millercenter.org/president/speeches
5 http://www.ars.usda.gov/Services/docs.htm?docid=8964
6 https://explore.data.gov/Foreign-Commerce-and-Aid/U-S-Overseas-Loans-and-Grants-Greenbook-/5gah-bvex
Most.Recent.Year.in.Data Earliest.Year.In.Data Status Dataset.Type
1          2008           NA Unused Dataset
2          2012           NA Unused Dataset
3          2011         2003 Unused     API
4          2012         1789 Unused Dataset
5          2012         1996 Unused Dataset
6          2010         1946 Unused Dataset
                              Documentation
1
2
3 https://github.com/stopfrisknyc/docs
4
5 http://www.ars.usda.gov/SP2UserFiles/Place/12354500/Data/SR25/sr25_doc.pdf
6 http://gbk.eads.usaidallnet.gov/about/
Existing.Work
1
2
3 http://www.forbes.com/sites/jasonoberholtzer/2012/07/17/stop-and-frisk-by-the-numbers/,http://www.dnainfo.com/new-york/20120604/new-york-city/port-authority-is-top-stop-and-frisk-hotspot-regardless-of-race
4
5
6
Tags Active
1 state-scale,politics n
2 historical,money n
3 historical,people y
4 historical,text y
5 n
6 y

更新日期:2020 年 8 月 12 日

2K+ 次浏览

开启你的职业生涯

完成课程获得认证

开始
广告