You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Anomalize R包遇报错:'arg'需为指定时间单位之一

Fixing "arg should be one of 'second', 'minute', 'hour', 'day', 'week', 'month', 'year'" Error in Anomalize (R 3.4.3)

Hey there, let's work through this error you're facing with the anomalize package in R 3.4.3. That error message is telling you two key things: first, there's a problem with the time frequency argument you're using, and second, since R 3.4.3 is pretty outdated (released back in 2017), version compatibility with newer anomalize and its dependencies is likely playing a role too. Here's how to fix it step by step:

1. Double-check your time unit arguments (singular only!)

The error is triggered because you probably used a plural time unit (like "days" instead of "day") in a function like time_decompose() or anomalize(). The package strictly expects the singular versions listed in the error message: second, minute, hour, day, week, month, year.

For example, if your original code looked like this:

your_data %>% time_decompose(metric_column, frequency = "weeks", trend = "months")

You need to adjust it to use singular units:

your_data %>% time_decompose(metric_column, frequency = "week", trend = "month")

2. Roll back to package versions compatible with R 3.4.3

Newer releases of anomalize and its core dependency tibbletime dropped support for R versions older than 3.5.x. To get things working, you'll need to install older, compatible versions of these packages using devtools:

First, install an older version of devtools that works with R 3.4.3 (if you don't have it already):

install.packages("devtools")

Then install the compatible package versions:

# Install tibbletime v0.1.2 (works with R 3.4.x)
devtools::install_version("tibbletime", version = "0.1.2", repos = "http://cran.us.r-project.org")

# Install anomalize v0.1.1 (compatible with tibbletime 0.1.2)
devtools::install_version("anomalize", version = "0.1.1", repos = "http://cran.us.r-project.org")

3. Ensure your data is formatted as a proper time-based tibble

Anomalize relies on tibbletime to handle time series data correctly. If your date column isn't properly recognized as a time index, it can cause unexpected argument errors. Format your data like this:

library(tibbletime)

# Convert date column to Date type (adjust to POSIXct if using datetime)
your_data <- your_data %>%
  mutate(date_column = as.Date(date_column)) %>%
  # Mark the date column as the time index
  as_tbl_time(index = date_column)

Final Check

After making these changes, re-run your anomaly detection code. The combination of fixing the time unit arguments, using compatible package versions, and ensuring proper time series formatting should resolve that error.

内容的提问来源于stack exchange,提问作者RPisco

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 06:57:18