提取' double'的y值物品。 r

发布于 2025-02-05 08:06:16 字数 196 浏览 3 评论 0原文

我使用CO2数据集来举例说明。

co2_dec <- decompose(co2)
co2_trend <- co2_dec$trend
typeof(co2_trend)

我想提取co2_trend项目的y值。

感谢您的时间。

I use co2 dataset to exemplify.

co2_dec <- decompose(co2)
co2_trend <- co2_dec$trend
typeof(co2_trend)

And I want to extract Y values of co2_trend item.

Thanks for your time.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

征棹 2025-02-12 08:06:17

您可以做的是co2_trendas.data.frame。然后,您在数据框中具有像这样的“ y值”中的值:

co2_dec <- decompose(co2)
co2_trend <- co2_dec$trend
co2_trend <- as.data.frame(co2_trend)
colnames(co2_trend) <- "trend"
co2_trend$trend

输出head(co2_trend,15)

      trend
1        NA
2        NA
3        NA
4        NA
5        NA
6        NA
7  315.8613
8  315.9175
9  315.9767
10 316.0696
11 316.1967
12 316.3287
13 316.4558
14 316.5687
15 316.6275

What you can do is make as.data.frame of the co2_trend. Then you have the values in a dataframe which are your "Y values" like this:

co2_dec <- decompose(co2)
co2_trend <- co2_dec$trend
co2_trend <- as.data.frame(co2_trend)
colnames(co2_trend) <- "trend"
co2_trend$trend

Output head(co2_trend, 15):

      trend
1        NA
2        NA
3        NA
4        NA
5        NA
6        NA
7  315.8613
8  315.9175
9  315.9767
10 316.0696
11 316.1967
12 316.3287
13 316.4558
14 316.5687
15 316.6275
牵你手 2025-02-12 08:06:17

我正在阅读您的帖子中的评论,并且(如果我很好地了解您)您已经拥有了想要的东西。您说您想要CO2_TREND中的所有值,并且可以看到CO2_TREND是双对象。

typeof(co2_trend)
[1] "double"

因此,您可以说(例如)CO2_trend [1:10]并获取实际的十个第一个数字。 则包括一些NA

co2_trend[1:10]
 [1]       NA       NA       NA       NA       NA       NA 315.8613 315.9175 315.9767 316.0696

在您的情况下,如果您不想要co2_trend的桌子式结构,

co2_trend %>% as.vector

,您可以使用:这将为您从头到尾提供所有数字:

  [1]       NA       NA       NA       NA       NA       NA 315.8613 315.9175 315.9767 316.0696 316.1967 316.3287
 [13] 316.4558 316.5687 316.6275 316.6617 316.6900 316.7225 316.7667 316.8163 316.8867 316.9450 316.9863 317.0167
 [25] 317.0412 317.0954 317.1671 317.2633 317.3708 317.4508 317.5288 317.6083 317.6921 317.7862 317.8504 317.9033

如果不是您想要的,请让我知道可以帮助您:)

I was reading the comments in your post and (if I understood you well) you already have what you want. You said you want all values from co2_trend and you can see that co2_trend is a double object.

typeof(co2_trend)
[1] "double"

In consequence, you can say (for example) co2_trend[1:10] and get the actual ten first numbers. Which in your case includes some NA's

co2_trend[1:10]
 [1]       NA       NA       NA       NA       NA       NA 315.8613 315.9175 315.9767 316.0696

If you don´t want the table-like structure of co2_trend, you can use:

co2_trend %>% as.vector

Which will give you all the numbers from start to end:

  [1]       NA       NA       NA       NA       NA       NA 315.8613 315.9175 315.9767 316.0696 316.1967 316.3287
 [13] 316.4558 316.5687 316.6275 316.6617 316.6900 316.7225 316.7667 316.8163 316.8867 316.9450 316.9863 317.0167
 [25] 317.0412 317.0954 317.1671 317.2633 317.3708 317.4508 317.5288 317.6083 317.6921 317.7862 317.8504 317.9033

Please let me know if this is not what you wanted so I can help you :)

隔岸观火 2025-02-12 08:06:17

似乎已经回答了,但这是您拥有的另一个选择:

co2_dec <- decompose(co2)
co2_trend <- co2_dec$trend
typeof(co2_trend)

y <- co2_trend[1:length(co2_trend)]
dt <- data.frame(y)

Seems already answered, but this is another option you have:

co2_dec <- decompose(co2)
co2_trend <- co2_dec$trend
typeof(co2_trend)

y <- co2_trend[1:length(co2_trend)]
dt <- data.frame(y)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文