title: Lowess function and plyr
body: <p>I am working with a data frame I created and want to expand it to include a lowess fit. I have been able to add a lowess curve to the plot of my data along with an lm fit but I cannot figure out how to add the lowess values to my data frame.
  Please forgive the ugliness of my code as I do everything by brute force (i.e. suggestions for simplification/efficiency are appreciated.) I apologize as I am not allowed to post images. I have a scatterplot with an lm fit yielding an R^2 of .7897 and a lowess curve which well replicates the qqplot of the lm fit. When I get a reputation of "10" I will post it for edification/ease of visualization:</p>
  
  <pre><code>##Read in Data
  OPM.df &lt;- read.csv("On Peak Mod TMAX.csv", header = TRUE)
   ## Data frame 2008-2012
  OPM5.df &lt;- OPM.df[4606:6140,]
  ##Verify headings
  OPM5.df[1,]
  SummerOPM5.df &lt;- OPM5.df[month(OPM5.df$Date) &gt;= 6 &amp; month(OPM5.df$Date) &lt;= 9, ]
  ##@Fit Linear Regression to Data
  fitsummerX &lt;- lm(SummerOPM5.df$MaxLoad~SummerOPM5.df$TMAX)
  summary(fitsummerX)
  ##Plot data 
  windows()
  plot(SummerOPM5.df$TMAX, SummerOPM5.df$MaxLoad, main="Linear Regression Adjusted R-     squared: 0.7897",)
  ## Add fit lines
  abline(fitsummerX, col="red") # regression line (y~x) 
  lines(lowess(SummerOPM5.df$TMAX,SummerOPM5.df$MaxLoad), col="blue") # lowess line (x,y)
  
  ## plyr augmentation of df
  SummerOPM5.df &lt;- ddply(SummerOPM5.df, .(Date, MaxLoad, TMAX, OnPeakTotal), transform,
      Lowess = (lowess(TMAX,MaxLoad)$y))
  ##Verify headings and values
  SummerOPM5.df [1:5,]
  </code></pre>
  
  <p>This gives the following:</p>
  
  <pre><code>Date        MaxLoad  TMAX OnPeakTotal Lowess
  1 2008-06-02    2880 214.0       43307   2880
  2 2008-06-03    2860 197.0       43166   2860
  3 2008-06-04    2787 172.5       42088   2787
  4 2008-06-05    2902 216.5       43333   2902
  5 2008-06-06    3078 275.0       45325   3078
  </code></pre>
  
  <p>The Lowess values are the same as the MaxLoad</p>
  
  <p>If I run the lowess seperately:</p>
  
  <pre><code>Lowess = (lowess(SummerOPM5.df$TMAX,SummerOPM5.df$MaxLoad))
  
  Lowess$y[1:5]
  </code></pre>
  
  <p>I get this:</p>
  
  <pre><code>[1] 2522.221 2569.523 2603.625 2622.795 2622.795
  </code></pre>
  
  <p>Where the vector is in rank order. 
  .
  I am unsure if it preserves the sequence otherwise so am unsure how to fit this to the corresponding rows of my data frame.</p>
  
  <p>Suggestions?</p>