2014-01-22 34 views
0

我有以下的载体和ACF功能(包quantmod,XML,动物园)lenght两个对象的列

L<- 1 
theurl <- "http://www.iasg.com/groups/group/transtrend/program/transtrend-diversified- 
trend-program-enhanced-risk-usd" 
tables <- readHTMLTable(theurl) 
n.rows <- unlist(lapply(tables, function(t) dim(t)[1])) 
MONTHLYPERFORMANCE<-tables[[which.max(n.rows)]] 
z<- as.data.frame(MONTHLYPERFORMANCE); 
z$Year<-NULL 
z$YTD <- NULL 
z$DD <- NULL 
z <- z[nrow(z):1,]; 
s<-as.vector(t(z)) 
w<-as.numeric(s) 
p<-na.omit(w) 
x<-(p*0.01*L) 
d<-length(na.omit(x)) 
x<- x[1:d] 
#DETREND+DENOISE 
s<-detrend(x, tt = 'linear', bp = c()) 
#AUTOCORRELATION 
a<-acf(x) 
b<-a[[1]] 
c<-(b[2:length(b)]) 
posssignificance_level<-qnorm((1+0.95)/2)/sqrt(sum(!is.na(x))) 
posssignificance_level 
negsignificance_level<- -posssignificance_level 
negsignificance_level 
poscorr<-which(posssignificance_level<c) 
negcorr<-which(negsignificance_level>c) 
posautorrelation <- if(length(poscorr) == 0) Lag(s,0) else na.omit(posautorrelation <- 
Lag(s, poscorr)) 
negautorrelation <- if(length(negcorr) == 0) Lag(s,0) else na.omit(negautorrelation <- 
Lag(s, negcorr)) 

然后我要让所有系列产生从posautorrelation和negautorrelation采取任何从posautorrelation和negautorrelation的最小行数由下面表达式

shortest <- min(length(posautorrelation), length(negautorrelation)) 
posautorrelation <- tail(posautorrelation, shortest) 
negautorrelation <- tail(negautorrelation, shortest) 
tpos <-na.omit(posautorrelation); rownames(tpos)<-NULL 
tneg <-na.omit(negautorrelation); rownames(tneg)<-NULL 

这种运作良好时我只有一个系列的正和负的另一个。然而,如果“posautorrelation”或“negautorrelation”产生多于一列,则最短函数将不同列的数行相加,从而阻碍来自上面的“最短”表达式。是否有一种“最短”的方法来考虑posautorelation的一列和negautorrelation的相同。

回答

0
shortest <- min(length(posautorrelation[,1]), length(negautorrelation[,1]))