title: How to track a change of a data in r?
body: <p>I am struggling to find the solution for a tracking problem in r.</p>
  
  <p>I have a daily dataframe that consists of rows representing that a package is located somewhere. I have a <code>date</code>, a <code>package_id</code> and a <code>location_id</code> in three columns. Location_id is a numeric variable.</p>
  
  <p>It can happen that a number of days pass and the <code>location_id</code> does not change. However, I want to create a new dataframe where I can track the change in location_id. </p>
  
  <p>Let us suppose that the the following observations happen:</p>
  
  <pre><code>packake_id location_id date_id
  PACK001    123         2018-04-02
  PACK001    123         2018-04-03
  PACK001    436         2018-04-04
  </code></pre>
  
  <p>The new object I want to produce should include the the package_id, the "old" location_id, the date of the "last" 123 location_id, and the "new" location_id, and the date of the "first" 436 location_id.</p>
  
  <p>In the example it should be like this:</p>
  
  <pre><code>packake_id old_dat    old_location_id new_date    new_location_id
  PACK001    2018-04-03 123             2018-04-04  436
  </code></pre>
  
  <p>My first thought was to combine all dataframes into one df by package_id and by that I will get a number of columns with the different dates and locations. Then I can filter out the changes in location by not equal. But it seems too complicated for me.</p>
  
  <p>Thanks for your help!</p>