<html><body><div style="color:#000; background-color:#fff; font-family:arial, helvetica, sans-serif;font-size:10pt"><div style="font-family: arial, helvetica, sans-serif; font-size: 10pt; ">Benilton, novamente obrigado pela resposta e tempo. Antes de executar o seu código, porém, eu tentei rodar o seguinte:</div><div style="font-family: arial, helvetica, sans-serif; font-size: 10pt; "><br></div><div><div><font class="Apple-style-span" size="2" face="'Courier New', courier, monaco, monospace, sans-serif"><div>##</div><div>P <- 2000:2010</div><div>Rep <- letters[1:5]</div><div>TF <- 1:2</div><div>CC <- paste("H-",101:299,sep="")</div><div>a <- expand.grid(P=P,R=Rep,TF=TF,CC=CC)</div><div>a$y <- rnorm(nrow(a))</div><div>a$z <- runif(nrow(a))</div></font></div><div><font class="Apple-style-span" size="2" face="'Courier New', courier, monaco, monospace, sans-serif"><br></font></div><div><font class="Apple-style-span" size="2"
face="'Courier New', courier, monaco, monospace, sans-serif"># Alternativa 3</font></div><div><font class="Apple-style-span" size="2" face="'Courier New', courier, monaco, monospace, sans-serif">library(snow)</font></div><div><font class="Apple-style-span" size="2" face="'Courier New', courier, monaco, monospace, sans-serif">ncpu<-4</font></div><div><font class="Apple-style-span" size="2" face="'Courier New', courier, monaco, monospace, sans-serif">cl<-makeSOCKcluster(rep("localhost",ncpu))</font></div><div><font class="Apple-style-span" size="2" face="'Courier New', courier, monaco, monospace, sans-serif">clusterEvalQ(cl,library(zoo))</font></div><div><font class="Apple-style-span" size="2" face="'Courier New', courier, monaco, monospace, sans-serif">clusterExport(cl,'a')</font></div><div><font class="Apple-style-span" size="2" face="'Courier New', courier, monaco, monospace, sans-serif"><br></font></div><div><font class="Apple-style-span"
size="2" face="'Courier New', courier, monaco, monospace, sans-serif">ind<-split(seq(nrow(a)),list(a$R,a$CC,a$TF))</font></div><div><font class="Apple-style-span" size="2" face="'Courier New', courier, monaco, monospace, sans-serif">a.2<-parLapply(cl,ind,function(i,k){</font></div><div><font class="Apple-style-span" size="2" face="'Courier New', courier, monaco, monospace, sans-serif"><span class="Apple-tab-span" style="white-space:pre"> </span>cbind(ma.y=c(rep(NA,k-1),rollmean(a$y[i],k)),</font></div><div><font class="Apple-style-span" size="2" face="'Courier New', courier, monaco, monospace, sans-serif"><span class="Apple-tab-span" style="white-space:pre"> </span>ma.z=c(rep(NA,k-1),rollmean(a$z[i],k)))</font></div><div><font class="Apple-style-span" size="2" face="'Courier New', courier, monaco, monospace, sans-serif"><span class="Apple-tab-span" style="white-space:pre"> </span>},k=3)</font></div><div><font class="Apple-style-span" size="2"
face="'Courier New', courier, monaco, monospace, sans-serif">a.2.1<-cbind(a,do.call(rbind,a.2))</font></div><div><font class="Apple-style-span" size="2" face="'Courier New', courier, monaco, monospace, sans-serif">a.2.2<-na.omit(a.2.1)</font></div></div><div style="font-family: arial, helvetica, sans-serif; "><div style="font-size: 12pt; font-family: 'times new roman', 'new york', times, serif; "><br><br></div><div class="yui_3_2_0_21_132014209157957"><font class="Apple-style-span" face="arial, helvetica, sans-serif" size="2">Eu fiz um split dos índices para depois juntar as médias móveis 'a.2' na base 'a'. Tudo vai muito bem até que ao juntar as duas partes, quando para algumas linhas os valores ficam incorretos.</font></div><div class="yui_3_2_0_21_132014209157957"><font class="Apple-style-span" face="arial, helvetica, sans-serif" size="2"><br></font></div><div class="yui_3_2_0_21_132014209157957"><font class="Apple-style-span" face="arial,
helvetica, sans-serif" size="2">Uma outra tentativa foi:</font></div><div class="yui_3_2_0_21_132014209157957"><font class="Apple-style-span" face="arial, helvetica, sans-serif" size="2"><br></font></div><div class="yui_3_2_0_21_132014209157957"><font class="Apple-style-span" size="2" face="'Courier New', courier, monaco, monospace, sans-serif">##</font></div><div class="yui_3_2_0_21_132014209157957"><font class="Apple-style-span" size="2"><div class="yui_3_2_0_21_132014209157957" style="font-family: 'Courier New', courier, monaco, monospace, sans-serif; "><font class="Apple-style-span" face="'Courier New', courier, monaco, monospace, sans-serif"># Alternativa 4</font></div><div class="yui_3_2_0_21_132014209157957" style="font-family: 'Courier New', courier, monaco, monospace, sans-serif; "><font class="Apple-style-span" face="'Courier New', courier, monaco, monospace, sans-serif">ma.fun<-function(x,k){</font></div><div
class="yui_3_2_0_21_132014209157957" style="font-family: 'Courier New', courier, monaco, monospace, sans-serif; "><font class="Apple-style-span" face="'Courier New', courier, monaco, monospace, sans-serif"> c(rep(NA,k-1),rollmean(x,k))</font></div><div class="yui_3_2_0_21_132014209157957" style="font-family: 'Courier New', courier, monaco, monospace, sans-serif; "><font class="Apple-style-span" face="'Courier New', courier, monaco, monospace, sans-serif">}</font></div><div class="yui_3_2_0_21_132014209157957" style="font-family: 'Courier New', courier, monaco, monospace, sans-serif; "><font class="Apple-style-span" face="'Courier New', courier, monaco, monospace, sans-serif"><br></font></div><div class="yui_3_2_0_21_132014209157957" style="font-family: 'Courier New', courier, monaco, monospace, sans-serif; "><font class="Apple-style-span" face="'Courier New', courier, monaco, monospace, sans-serif">library(data.table)</font></div><div
class="yui_3_2_0_21_132014209157957" style="font-family: 'Courier New', courier, monaco, monospace, sans-serif; "><font class="Apple-style-span" face="'Courier New', courier, monaco, monospace, sans-serif">a.3<-data.table(a)</font></div><div class="yui_3_2_0_21_132014209157957" style="font-family: 'Courier New', courier, monaco, monospace, sans-serif; "><font class="Apple-style-span" face="'Courier New', courier, monaco, monospace, sans-serif">a.3.1<-a.3[,list(P,y=ma.fun(y,k=3),z=ma.fun(z,k=3)),by=list(R,CC,TF)]</font></div><div class="yui_3_2_0_21_132014209157957" style="font-family: 'Courier New', courier, monaco, monospace, sans-serif; "><font class="Apple-style-span" face="'Courier New', courier, monaco, monospace, sans-serif">a.3.2<-na.omit(a.3.1)</font></div><div class="yui_3_2_0_21_132014209157957" style="font-family: 'Courier New', courier, monaco, monospace, sans-serif; "><br></div><div class="yui_3_2_0_21_132014209157957"
style="font-family: 'Courier New', courier, monaco, monospace, sans-serif; "><br></div><div class="yui_3_2_0_21_132014209157957"><font class="Apple-style-span" face="arial, helvetica, sans-serif">Mas na base original tem algumas combinações de níveis inexistentes e dá erro, avisando que estes 'tratamentos' tem comprimento zero. Como eu poderia lidar com isso na função 'ma.fun'?</font></div><div class="yui_3_2_0_21_132014209157957"><font class="Apple-style-span" face="arial, helvetica, sans-serif"><br></font></div><div class="yui_3_2_0_21_132014209157957"><font class="Apple-style-span" face="arial, helvetica, sans-serif">Grato,</font></div><div class="yui_3_2_0_21_132014209157957"><font class="Apple-style-span" face="arial, helvetica, sans-serif">Rubem</font></div><div class="yui_3_2_0_21_132014209157957" style="font-family: 'Courier New', courier, monaco, monospace, sans-serif; "><br></div><div class="yui_3_2_0_21_132014209157957"
style="font-family: 'Courier New', courier, monaco, monospace, sans-serif; "><br></div></font></div></div></div></body></html>