y_duck 我有一个 Base R 的解决办法,构造一个 ts 类型的数据对象,ts()
是内置的函数,给定数据,知道初始时间,采样频率的情况下,构造一个时间序列。
# 分钟级
x <- ts(
data = rnorm(100),
start = c(2017, 1),
frequency = 365.25 / (1/(24*60)), # 每隔 1/(24*60) 天(即1分钟)采样一个点
class = "ts", names = "搜索次数"
)
ts()
函数的 start 和 frequency 参数很关键,前者指定了时间单位是天,后者指定每个时间单位下的数据点的数量。
start
the time of the first observation. Either a single number or a vector of two numbers (the second of which is an integer), which specify a natural time unit and a (1-based) number of samples into the time unit. See the examples for the use of the second form.
frequency
the number of observations per unit of time.
其中 365.25 是因为每隔 4 年有 366 天,平均下来,每年算 365.25 天。楼主可根据需要稍作调整。