title: Scala Dataframe window lag function on condition
body: <p>I have a dataframe with following records.</p>
  
  <pre><code>id   col1         time
  A      1    2017-12-23 09:00
  A-1    1    2017-12-23 11:00
  A-1    1    2017-12-23 10:00
  A      2    2017-12-23 08:00
  A      3    2017-12-23 07:00
  A-2    4    2017-12-23 12:00
  A-1    4    2017-12-23 12:00
  B      1    2017-12-23 09:00
  B-1    1    2017-12-23 11:00
  B-1    1    2017-12-23 10:00
  B      2    2017-12-23 08:00
  B      3    2017-12-23 07:00
  B-2    4    2017-12-23 12:00
  B-1    4    2017-12-23 12:00
  </code></pre>
  
  <p>I would like to get the lag features from the above data frame but with a condition on "id" column.Is it possible to give condition on lag feature without changing the records?. I have tired like below</p>
  
  <pre><code>val window = Window.partitionBy("id").orderBy("time")
  val resultDF = DF.withColumn("col1_lag",lag(DF("col1"), 1).over(window))
  </code></pre>
  
  <p>The above code will result in giving the lag features based on grouped id,I would  like to consider the values with "-" are child's and they need the parents lag feature. Eg : Row with id A-1(child) needs the value of A(parent) appeared before it.</p>
  
  <p>The expected result should be like below.</p>
  
  <pre><code>id   col1         time           col1_lag
  A      3    2017-12-23 07:00       null
  A      2    2017-12-23 08:00       3
  A      1    2017-12-23 09:00       2
  A-1    1    2017-12-23 10:00       1   
  A-1    1    2017-12-23 11:00       1  
  A-1    4    2017-12-23 12:00       1
  A-2    4    2017-12-23 12:00       1
  B      3    2017-12-23 07:00       null 
  B      2    2017-12-23 08:00       3   
  B      1    2017-12-23 09:00       2
  B-1    1    2017-12-23 10:00       1
  B-1    1    2017-12-23 11:00       1 
  B-1    4    2017-12-23 12:00       1
  B-2    4    2017-12-23 12:00       1
  </code></pre>