从列表中递归选择并递归地应用于表达式的表达式元素

时间:2014-01-30 17:19:35

标签: r

包裹(wmtsa,gtools,插入符号)

我有以下向量,并且在以下函数下面

z2 <- c(-0.1100, 0.1800, 0.0620, 0.1000,-0.0730,-0.1310, 0.2170,-0.0680,-0.0840,   
-0.1350,-0.3070, 0.0670, 0.1360, 0.1000,-0.0150, 0.2450,0.1190,-0.0560, -0.0600,  
-0.1400, -0.0420,  0.1250,  0.0060, -0.0280,-0.0620, -0.0010,  0.0880, -0.0180,  0.0720,  
0.3160, -0.0270, -0.0460,0.0600, -0.0300,  0.0550, -0.0560,  0.1780,  0.0200,  0.0070,  
0.0430)

Wavs4 <- wavMODWT(z2, wavelet="s4", n.levels=ilogb(length(z), base=2),position=list 
(from=1, by=1,units=character()), units=character(),title.data=character(), 
documentation=character(), keep.series=FALSE)

MRD4<-wavMRD(Wavs4, level=NULL, osc=NULL)

wavs4access<-as.matrix(MRD4)

wavs4access<-as.matrix(wavs4access)

Dxu4 <- wavs4access [,"D1"]
Dxi4 <- wavs4access [,"D2"]
Dxa4 <- wavs4access [,"D3"]

#From above selected combinations

a <- c("Dxi4","Dxu4","Dxa4")
b <- combinations(3, 2, a, set=TRUE, repeats.allowed=FALSE) 

#I extract the coefficients from comb...

d1 <- c(b[[1,1]],b[[1,2]])
d2 <- c(b[[2,1]],b[[2,2]])
d3 <- c(b[[3,1]],b[[3,2]])

#I create a list

dlist<-list(d1=d1,d2=d2,d3=d3)

我想在下面的表达式pastevar中应用上面的dlist,所以我生成一个表达式,可以使用函数递归循环所有d值,而不是写下面三次以下表达式,然后每次都运行该函数

pastevar <- paste(c("z2[1:length(z2)] ~ ", paste(d1, collapse=" + ")))
X <- model.matrix(as.formula(pastevar))[,-1]
X <- data.frame(X)
Y <- z2[1:length(z2)]

谢谢

0 个答案:

没有答案