R:如何在小标题中访问小标题?

编程入门 行业动态 更新时间:2024-10-28 09:29:30
本文介绍了R:如何在小标题中访问小标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在阅读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:如何在小标题中访问小标题?

本文发布于:2023-10-07 22:22:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1470680.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:小标题   如何在

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!