1.Web data
A. Websites that have APIs
> Library (WDI)
Load the required thread bundle: Rjsonio
> Library (Rjsonio)
> Library (WDI)
> Wdi_datasets <-wdisearch ()
> Head (wdi_datasets)
Indicator
[1,] "BG. GSR. Nfsv.gd. ZS "
[2,] "BM. Klt. Dinv.gd. ZS "
[3,] "BN. CAB. Xoka.gd. ZS "
[4,] "BN. CUR. GDPM. ZS "
[5,] "BN. GSR. Fcty. Cd. ZS "
[6,] "BN. Klt. Dinv. Cd. ZS "
Name
[1,] "Trade in services (% of GDP)"
[2,] "Foreign Direct investment, net outflows (% of GDP)"
[3,] "Current account balance (% of GDP)"
[4,] "Current account balance excluding net official capital grants (% of GDP)"
[5,] "Net Income (% of GDP)"
[6,] "Foreign Direct investment (% of GDP)"
> wdi_trade_in_services <-wdi (indicator = "BG. GSR. Nfsv.gd. ZS ")
> str (wdi_trade_in_services)
' Data.frame ': 1848 obs. of 4 variables:
$ ISO2C:CHR "1 A" "1 A" "1 A" "1 a" ...
$ COUNTRY:CHR "Arab World", "Arab World", "Arab World", "Arab World" ...
$ BG. GSR. Nfsv.gd. Zs:num 15 17.1 19.1 17.4 18.5 ...
$ year:num 2011 2010 2009 2008 2007 ...
Use to access stock quotes
> Library (QUANTMOD)
> Options (Getsymbols.auto.assign=false)
> Microsoft <-getsymbols ("MSFT")
> Head (Microsoft)
MSFT. Open MSFT. High MSFT. Low
2007-01-03 29.91 30.25 29.40
2007-01-04 29.70 29.97 29.44
2007-01-05 29.63 29.75 29.45
2007-01-08 29.65 30.10 29.53
2007-01-09 30.00 30.18 29.73
2007-01-10 29.80 29.89 29.43
MSFT. Close MSFT. Volume MSFT. Adjusted
2007-01-03 29.86 76935100 22.96563
2007-01-04 29.81 45774500 22.92717
2007-01-05 29.64 44607200 22.79642
2007-01-08 29.93 50220200 23.01947
2007-01-09 29.96 44636600 23.04254
2007-01-10 29.66 55017400 22.81180
B. Crawling Web pages
Grab Justin Rao's website from 2002 to 2008 NBA payroll data
> Salary_url <-"http://www.justinmrao.com/salary_data.csv"
> Local_copy <-"my local Copy.csv"
> Download.file (salary_url,local_copy)
Trying URL ' Http://www.justinmrao.com/salary_data.csv '
Content type ' text/plain ' length 390643 bytes (381 KB)
Downloaded 381 KB
> Salary_data <-read.csv (local_copy)
R language Learning (10) Get data