R language Learning (10) Get data

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.