我使用if函数编写了一个代码,每个if循环的结果(其中212个)给出了" n"或者来自acf图的滞后总和。我想找到最小值,然后在if-loop
中调用相应的命令以下是使用前两个if循环的示例:
orderWA1<-c(0,0,0)
orderWS1<-c(0,0,0)
ArimaW1 <- Arima(N, order= orderWA1, seasonal=list(order=orderWS1), method="ML")
if(aslog=="y"){Arimafit<-exp(fitted(ArimaW1))}else{Arimafit<-fitted(ArimaW1)}
nnn<-c(N)
arimab<-c(Arimafit)
fullres<-nnn-arimab
v<-acf(fullres,plot=FALSE)
w<-pacf(fullres,plot=FALSE)
if(v$acf[2]>0.4|v$acf[2]<(-0.4)|v$acf[3]>0.4|v$acf[3]<(-0.4)|v$acf[4]>0.4|v$acf[4]<(-0.4)|v$acf[5]>0.4|v$acf[5]<(-0.4)|v$acf[6]>0.4|v$acf[6]<(-0.4)|v$acf[7]>0.4|v$acf[7]<(-0.4)|w$acf[1]>0.4|w$acf[1]<(-0.4)|w$acf[2]>0.4|w$acf[2]<(-0.4)|w$acf[3]>0.4|w$acf[3]<(-0.4)|w$acf[4]>0.4|w$acf[4]<(-0.4)|w$acf[5]>0.4|w$acf[5]<(-0.4)|w$acf[6]>0.4|w$acf[6]<(-0.4))
a01<-"n" else
{a01<-sum(abs(v$acf[2:7]))
b01<-sum(abs(w$acf[1:6]))}
orderWA2<-c(0,0,0)
orderWS2<-c(0,0,1)
ArimaW1 <- Arima(N, order= orderWA2, seasonal=list(order=orderWS2), method="ML")
if(aslog=="y"){Arimafit<-exp(fitted(ArimaW1))}else{Arimafit<-fitted(ArimaW1)}
nnn<-c(N)
arimab<-c(Arimafit)
fullres<-nnn-arimab
v<-acf(fullres,plot=FALSE)
w<-pacf(fullres,plot=FALSE)
if(v$acf[2]>0.4|v$acf[2]<(-0.4)|v$acf[3]>0.4|v$acf[3]<(-0.4)|v$acf[4]>0.4|v$acf[4]<(-0.4)|v$acf[5]>0.4|v$acf[5]<(-0.4)|v$acf[6]>0.4|v$acf[6]<(-0.4)|v$acf[7]>0.4|v$acf[7]<(-0.4)|w$acf[1]>0.4|w$acf[1]<(-0.4)|w$acf[2]>0.4|w$acf[2]<(-0.4)|w$acf[3]>0.4|w$acf[3]<(-0.4)|w$acf[4]>0.4|w$acf[4]<(-0.4)|w$acf[5]>0.4|w$acf[5]<(-0.4)|w$acf[6]>0.4|w$acf[6]<(-0.4))
a02<-"n" else
{a02<-sum(abs(v$acf[2:7]))
b02<-sum(abs(w$acf[1:6]))}
我希望能够找到所有不给予的东西的名字&#34; n&#34;
所以我想要一个看起来像
的矢量a01 a02 a03 a04 a06 a08 etc
它只选择数字
答案 0 :(得分:2)
尝试
l1 <- mget(ls(pattern="^a\\d+"))
library(gtools)
mixedsort(names(unlist(l1[sapply(l1, `==`, "y")])))
# [1] "a1" "a2" "a4" "a5" "a6" "a8" "a11" "a12" "a13" "a15"