title: Shifting a vector
body: <p>I have a data frame and I would like to 'align' each column so that the maximum value for each column is on the same row.</p>
  
  <p>I was trying to do this using base functionality, but am getting the wrong results, ie. just overwriting and not shifting.  I just found the Lag function in Hmisc, however, I am sure there is a way to do this in base and I"m just thinking about it wrong.  I would prefer this, as when I try to run this later on another computer with a different verison of R there are always some package that aren't supported.</p>
  
  <p>Thanks for any help,</p>
  
  <pre><code>maxIndices&lt;-apply(df,2,function(x){
  maxInt&lt;-max(x,na.rm=T)
  maxInt_indx&lt;-which(x==maxInt) 
  })
  maxMaxIndex&lt;-max(maxIndices)
  minMaxIndex&lt;-min(maxIndices)
  ##
  apply(df,2,function(x){
    maxInt&lt;-max(x,na.rm=T)
    maxInt_indx&lt;-which(x==maxInt)
   shift&lt;-maxMaxIndex-maxInt_indx
  shifted_vec&lt;-c(rep(NA,times=shift), x[1:length(x)+shift]) ## this is producing the wrong results
  # shifted_vec&lt;-Lag(x,shift) # is there a way to do this using just base functionality
  })
  </code></pre>