我正在阅读Hadley的文章: r4ds.had.co.nz/tibbles. html
I am reading Hadley's: r4ds.had.co.nz/tibbles.html
但是,我仍然很难在小标题中引用小标题.
However, I am still having difficulty referencing a tibble in a tibble.
> library(tidyquant) > f <- tq_get("F", get="key.ratios") > f # A tibble: 7 x 2 section data <chr> <list> 1 Financials <tibble [150 x 5]> 2 Profitability <tibble [170 x 5]> 3 Growth <tibble [160 x 5]> 4 Cash Flow <tibble [50 x 5]> 5 Financial Health <tibble [240 x 5]> 6 Efficiency Ratios <tibble [80 x 5]> 7 Valuation Ratios <tibble [40 x 5]> > f["Financials"] Error: Column `Financials` not found > f[["Financials"]] NULL > f$Financials NULL Warning message: Unknown or uninitialised column: 'Financials'. > f$data[[f$section == 'Financials']] Error in f$data[[f$section == "Financials"]] : attempt to select less than one element in integerOneIndex > f$data[[1]]$Financials NULL Warning message: Unknown or uninitialised column: 'Financials'.推荐答案
来自 tidyquant 的文档,并使用tq_get(symbol, get = "key.ratios")返回嵌套的小标题.在小标题的数据"列内还有其他表,其中包含列:section,sub.section,group,category和date.
From tidyquant's documentation, using tq_get(symbol, get = "key.ratios") returns a nested tibble. Inside the tibble's "data" column are other tables with columns: section, sub.section, group, category, and date.
您最初试图访问主数据框中的财务"列,但不存在这样的列(它只有部分"和数据").而是,财务"是部分"列的元素(行).我想相反,您想要的是:
You were originally trying to access a column called "Financials" in the main data frame, but no such column exists (it has only "section" and "data"). "Financials" is, instead, an element (row) of the "section" column. I think instead you want:
filter(f, section == "Financials") %>% unnest()更多推荐
R:如何在小标题中访问小标题?
发布评论