<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
  <title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Jens,<br>
<br>
I am new to R as you are. I noticed in your code you brute force the
lag of your data series.&nbsp; <br>
<pre wrap=""><font size="-1">diffAA&lt;-logAA[1:100]-logAA[2:101]
diffA&lt;-logA[1:100]-logA[2:101]
diffBBB&lt;-logBBB[1:100]-logBBB[2:101]
</font>
You might look at the zoo package.&nbsp; It has some really good functions for time series as well.&nbsp; For example the lag operator lag.zoo.

My example converts my price data.frame column(variable) gas$price to a zoo object, lags one day,converts it to a vector to get rid of some of the zoo class components, and assigns it to PriceLag1 in my data.frame.  I do some statements looking at daily prices changes +, -, and NA.  The NA is because some time series functions do not handle missing values.  Also, my code is for a technical analysis project I am working on.  In this example I loose one degree of freedom at the beginning of my data series, hence the k=-1.  

<font size="-1">#lagging Gas Prices pair today with yesterday hence k=-1 below
gas$PriceLag1&lt;-as.vector(lag.zoo(as.zoo(gas$Price),k=-1,na.pad=TRUE)); # use zoo so can pad on the run
gas$PriceD[which(gas$Price&gt;gas$PriceLag1)]&lt;-1;  # Price_t&gt;Price_t-1 1
gas$PriceD[which(gas$Price&lt;gas$PriceLag1)]&lt;- -1;# Price_t&lt;Price_t-1 -1
gas$PriceD[which(gas$Price==gas$PriceLag1)]&lt;- 0;# Price_t=Price_t-1 0
gas$PriceD[which(gas$PriceLag1==NA)]&lt;- 0;# Handle the lost degrees of freedom
</font>
You might try
<font><font size="-1">diffAAA&lt;-logAAA-as.vector(lag.zoo(as.zoo(logAAA),k=-1, na.pad=TRUE));# diff today with the lag one day back

Using the zoo functions alleviates hard coding dimensions, inserting dimension tests, and adds dynamic reusable code functionality.  There also may be more efficient ways to use the zoo package that I have here, but it worked for me.

Good Luck
Joe

</font></font>

</pre>
</body>
</html>