简体   繁体   中英

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. 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:

Usage
measured_vars(x)

Arguments
x   
A tbl_ts.

Examples
measured_vars(pedestrian)

which strikes me as unhelpful. measured_vars is a generic function. It has one method: measured_vars.tbl_ts* My object is of class tbl_ts. GetAnywhere reports that it is an S3 method in the tsibble namespace:

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. But feasts::ACS also says it wants a tsibble, and I do not believe it is asking for nested tsibbles.

The ACF function expects the first parameter to be a tibble, and the second to be the variable name. 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

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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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