[英]Running a seasonal decomposition on multiple columns in R
I am learning to code in R and have been strugling to get something very simple to work. 我正在学习用R编写代码,一直在努力使工作变得非常简单。 I have a database with prices of products, each column represents the time series of a product. 我有一个包含产品价格的数据库,每个列代表一个产品的时间序列。 I want to run a Seasonal Decomposition of Time Series on each column and get the results in a list separated by product name. 我想在每列上运行时间序列的季节性分解,并在以产品名称分隔的列表中获得结果。
When I run the code below I get the error: 当我运行下面的代码时,出现错误:
Error in assign(paste(j), x[j]) <- (stl(dados_resumo[, x], s.window = "periodic")) : could not find function "assign<-" Assign(paste(j),x [j])<-(stl(dados_resumo [,x],s.window =“ periodic”))中的错误:找不到函数“ assign <-”
for (i in 1:3)
{
x <- (i)
for(j in colnames(df)){
assign(paste(j), x[j]) <- (stl(df[,x], s.window="periodic"))
}
}
I'm not sure what your data frame looks like, so I'll have a go at this manually. 我不确定您的数据框是什么样子,因此我将手动进行介绍。
Firstly, assign isn't a function, which is exactly what the error is telling you. 首先,assign不是函数,这正是错误告诉您的。
for( i in 1:length( df ) )
{
df$stl[i] <- stl( df[,i], s.window = "periodic" )
}
'assign<-' is not a function, however, 'assign' is; 'assign <-'不是函数,但是'assign'是; which is used in the form of assign(varname,varvalue,environment) for example, if you want to assign value "bigworld" to varible named x in global environment you can use 例如,它以assign(varname,varvalue,environment)的形式使用,如果要在全局环境中将值“ bigworld”分配给名为x的变量,则可以使用
assign(x,"bigworld",envir=.GlobalEnv)
envir can be set as envir = .GlobalEnv so that even in a function deep in stack or calling chain, you can assign value to var in global environment 可以将envir设置为envir = .GlobalEnv,以便即使在堆栈或调用链深处的函数中,也可以在全局环境中将值分配给var
the equation 等式
x = a
or 要么
x <- a
can also be used for assigning but inside the function, this will not affect the value globally, once the function is returned, x is removed 也可以用于赋值,但是在函数内部,这不会全局影响值,一旦返回函数,将x删除
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.