简体   繁体   English

R:tidyverts 中的错误和麦芽汁

[英]R: Errors and worts in the tidyverts

I have some data concerning events that take place at irregular intervals, where the only thing that matters is the order.我有一些关于不定期发生的事件的数据,其中唯一重要的是顺序。 I am trying to use some of the functions from the tidyverts universe (which replaces the forecast package), by declaring a sequence of consecutive integers as my time index.我试图通过将一系列连续整数声明为我的时间索引来使用 tidyverts Universe(它取代了 forecast 包)中的一些函数。 I've been getting an error I dont understand:我遇到了一个我不明白的错误:

 Error in UseMethod("measured_vars") : 
  no applicable method for 'measured_vars' applied to an object of class "c('double', 'numeric')"

the “measured_vars" function is in the tsibble package. (ACF and autoplot are from feasts ). Its documentation reads:了“measured_vars”功能是在tsibble包(ACF和自动绘制来自。 feasts )及其文件的读取。:

Usage
measured_vars(x)

Arguments
x   
A tbl_ts.

Examples
measured_vars(pedestrian)

which strikes me as unhelpful.这让我觉得毫无帮助。 measured_vars is a generic function. measure_vars 是一个通用函数。 It has one method: measured_vars.tbl_ts* My object is of class tbl_ts.它有一种方法: measured_vars.tbl_ts*我的对象属于 tbl_ts 类。 GetAnywhere reports that it is an S3 method in the tsibble namespace: GetAnywhere 报告它是 tsibble 命名空间中的 S3 方法:

function (x) 
{
    all_vars <- names(x)
    key_vars <- key_vars(x)
    idx_var <- index_var(x)
    setdiff(all_vars, c(key_vars, idx_var))
}
<bytecode: 0x0000023673afa460>
<environment: namespace:tsibble>

This code yields the same error:此代码产生相同的错误:

library("fpp3")
ind. <-1:4
data.  <-c(3,2,6,6)
data_ts <- as_tsibble(data.frame(ind., data.), index = "ind.")
autoplot(ACF(data_ts$data.))

I recognise that the function that throws the error, measured_vars , says it wants a tsibble and I am handing it a column in a tsibble.我认识到抛出错误的函数measured_vars变量表示它需要一个 tsibble 并且我正在将它放在 tsibble 中的一列。 But feasts::ACS also says it wants a tsibble, and I do not believe it is asking for nested tsibbles.但是盛宴::ACS也说它想要一个tsibble,我不相信它要求嵌套的tsibble。

The ACF function expects the first parameter to be a tibble, and the second to be the variable name. ACF函数要求第一个参数是 tibble,第二个是变量名。 You cannot pass in a column.您不能传入一列。 Use

autoplot(ACF(data_ts, data.))

I don't seem to see any other runnable code in your question so it's not clear what the first problem is, but do be mindful of the data types specified in the help pages.我似乎没有在您的问题中看到任何其他可运行代码,因此不清楚第一个问题是什么,但请注意帮助页面中指定的数据类型。 You can pass a tsibble to measured_vars您可以将 tsibble 传递给measured_vars的_vars

measured_vars(data_ts)
# [1] "data."

Note that these have different classes请注意,这些具有不同的类

class(data_ts)
# [1] "tbl_ts"     "tbl_df"     "tbl"        "data.frame"
class(data_ts$data.)
# [1] "numeric"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM