How to import csv file data from Github in R?


If you have a csv file on Github then it can be directly imported in R by using its URL but make sure that you click on Raw option on Github page where the data is stored. Many people do not click on Raw option therefore they read HTML instead of CSV and get confused. Here, I am sharing a public data set that contains the list of data sets. This data set has 12 variables. Now let’s import it −

> 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

Updated on: 12-Aug-2020

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements