gpt4 book ai didi

r - R 中的 Quantmod FRED 元数据

转载 作者:行者123 更新时间:2023-12-02 02:34:06 24 4
gpt4 key购买 nike

library(quantmod)

getSymbols("GDPC1",src = "FRED")

我正在尝试提取 FRED 中的数字经济/金融数据以及元数据。我正在尝试绘制 CPI 图表并将元数据作为标签/脚注。有没有办法使用 quantmod 包提取这些数据?

Title:               Real Gross Domestic Product
Series ID: GDPC1
Source: U.S. Department of Commerce: Bureau of Economic Analysis
Release: Gross Domestic Product
Seasonal Adjustment: Seasonally Adjusted Annual Rate
Frequency: Quarterly
Units: Billions of Chained 2009 Dollars
Date Range: 1947-01-01 to 2014-01-01
Last Updated: 2014-06-25 7:51 AM CDT
Notes: BEA Account Code: A191RX1

Real gross domestic product is the inflation adjusted value of the
goods and services produced by labor and property located in the
United States.

For more information see the Guide to the National Income and Product
Accounts of the United States (NIPA) -
(http://www.bea.gov/national/pdf/nipaguid.pdf)

最佳答案

您可以使用 getSymbools.FRED 正文中的相同代码,但将“.csv”更改为“.xls”,然后从 .xls 中读取您感兴趣的元数据文件。

library(gdata)

Symbol <- "GDPC1"
FRED.URL <- "http://research.stlouisfed.org/fred2/series"

tmp <- tempfile()
download.file(paste0(FRED.URL, "/", Symbol, "/downloaddata/", Symbol, ".xls"),
destfile=tmp)
read.xls(tmp, nrows=17, header=FALSE)
# V1 V2
# 1 Title: Real Gross Domestic Product
# 2 Series ID: GDPC1
# 3 Source: U.S. Department of Commerce: Bureau of Economic Analysis
# 4 Release: Gross Domestic Product
# 5 Seasonal Adjustment: Seasonally Adjusted Annual Rate
# 6 Frequency: Quarterly
# 7 Units: Billions of Chained 2009 Dollars
# 8 Date Range: 1947-01-01 to 2014-01-01
# 9 Last Updated: 2014-06-25 7:51 AM CDT
# 10 Notes: BEA Account Code: A191RX1
# 11 Real gross domestic product is the inflation adjusted value of the
# 12 goods and services produced by labor and property located in the
# 13 United States.
# 14
# 15 For more information see the Guide to the National Income and Product
# 16 Accounts of the United States (NIPA) -
# 17 (http://www.bea.gov/national/pdf/nipaguid.pdf)
<小时/>

您可以使用 grep 来搜索具有数据标题的行,而不是硬编码 nrows=17,并且子集仅包含在此之前的行。

dat <- read.xls(tmp, header=FALSE, stringsAsFactors=FALSE)
dat[seq_len(grep("DATE", dat[, 1])-1),]

unlink(tmp) # remove the temp file when you're done with it.

关于r - R 中的 Quantmod FRED 元数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24985267/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com