Hi,
I would like to speed up the following script somehow.
empiria<-function(zz){
greater<-which(zz[1:nrow(zz)]<2)
greater<-greater[diff(nagyobb)!=1]
smaller<-which(zz[1:nrow(zz)]> -2)
smaller<-kisebb[diff(kisebb)!=1]
cross<-sort(c(greater,smaller))
cross<-cross+1
cross<-cross[cross>2]
t_1nap<-c()
for(val in atlepes){
t_1nap<-c(t_1nap,abs(zz[[val]]-zz[[val-1]]))}
return(t_1nap)}
zz is a time series, with the function I am trying to find those elements where the time series becames greater than 2 or smaller than -2. For instance, in a series of 1,3,5 , I am interested only in the second element, not in the third. If I have that, then I substract the previous element from this. I suppose both the for loop and the way I am adding this values to a vector one-by-on makes the code considerably slower. Could someone suggest me a way to avoid them? Thank you,