日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

R语言学习(10)获取数据

發布時間:2024/1/17 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 R语言学习(10)获取数据 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1.Web數據

  a. 擁有API的網站

> library(WDI)
載入需要的程輯包: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 "1A" "1A" "1A" "1A" ...
$ 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 ...

  使用quantmod包可以訪問股票行情

> 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.抓取網頁

抓取Justin Rao的網站從2002年到2008年間的NBA工資數據

> 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)

轉載于:https://www.cnblogs.com/JaniceZD/p/7978425.html

總結

以上是生活随笔為你收集整理的R语言学习(10)获取数据的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。